Skip to content

Commit

Permalink
fix incorrect text_surface height
Browse files Browse the repository at this point in the history
  • Loading branch information
daelsepara committed Sep 8, 2021
1 parent 6ce6f9e commit 2ce6a82
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
38 changes: 24 additions & 14 deletions src/glyphs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ namespace Glyphs

auto space = 0;

TTF_SetFontStyle(font, current_style);

TTF_GlyphMetrics(font, ' ', NULL, NULL, NULL, NULL, &space);

for (auto i = 0; i < copy.length(); i++)
Expand All @@ -90,6 +92,8 @@ namespace Glyphs
{
if (word)
{
word = false;

auto subw = 0;

auto sub = copy.substr(start, i - start);
Expand All @@ -100,8 +104,6 @@ namespace Glyphs

TTF_SizeText(font, sub.c_str(), &subw, NULL);

word = false;

if (x + subw > width)
{
x = subw;
Expand All @@ -117,9 +119,16 @@ namespace Glyphs
if (c == '\t' || c == ' ')
{
x += space;

if (x > width)
{
x = 0;

lines += 1;
}
}

if (x > width || c == '\n' || c == '\r')
if (c == '\n' || c == '\r')
{
x = 0;

Expand Down Expand Up @@ -198,8 +207,6 @@ namespace Glyphs

TTF_SizeText(font, sub.c_str(), &subw, NULL);

word = false;

if (x + subw > width)
{
lines += 1;
Expand Down Expand Up @@ -266,6 +273,8 @@ namespace Glyphs

auto skip = TTF_FontLineSkip(font);

TTF_SetFontStyle(font, current_style);

TTF_GlyphMetrics(font, ' ', NULL, NULL, NULL, NULL, &space);

auto closeBold = false;
Expand All @@ -292,6 +301,8 @@ namespace Glyphs
{
if (word)
{
word = false;

auto subw = 0;

auto sub = copy.substr(start, i - start);
Expand All @@ -302,8 +313,6 @@ namespace Glyphs

TTF_SizeText(font, sub.c_str(), &subw, NULL);

word = false;

if (x + subw > width)
{
x = subw;
Expand All @@ -323,9 +332,16 @@ namespace Glyphs
if (c == '\t' || c == ' ')
{
x += space;

if (x > width)
{
x = 0;

lines += 1;
}
}

if (x > width || c == '\n' || c == '\r')
if (c == '\n' || c == '\r')
{
x = 0;

Expand Down Expand Up @@ -406,14 +422,8 @@ namespace Glyphs

TTF_SizeText(font, sub.c_str(), &subw, NULL);

word = false;

if (x + subw > width)
{
x = subw;

x += space;

lines += 1;

y = lines * skip;
Expand Down
2 changes: 1 addition & 1 deletion src/topics/book1.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
},
{
"title": "Spell List for Starting Characters",
"text": "<b>Animal Speech (Adventure)</b>\nYou are able to communicate using the secret speech of animals. The text will tell you when you can cast this spell.\n<b>Recharge: 50 silver</b>\n\n<b>Armour of Heaven (Combat)</b>\nGain a +3 bonus to one party member's Armour which lasts until the end of this battle.\n<b>Recharge: 50 silver</b>\n\n<b>Ice Bolt (Combat)</b>\nYou conjure a great block of ice and hurl it at your foe with magical strength. Make an immediate attack with a Fighting score of 8 against any opponent.\n<b>Recharge: 50 silver</b>\n\n<b>Poison Stream (Combat)</b>\nA sickly green poison jets from your hands. Make two immediate attacks with a Fighting score of 5, against two different opponents.\n<b>Recharge: 50 silver</b>\n\n<b>Unfailing Strike (Combat)</b>\nA pillar of energy sizzles into a single foe. Choose an opponent to lose 3 Health.\n<b>Recharge: 50 silver</b>\n\n<b>Wolf Spirit (Adventure)</b>\nYou summon the spirit of the wolf to help guide you from danger in the natural world. Cast this spell when you fail a Survival check. You gain an additional 3 automatic successes for this check only.\n<b>Recharge: 75 silver</b>\n\n<b>Magic Cabinet (Adventure)</b>\nYou summon a magic cabinet made of purple wood. You can use this cabinet to access The Vault, storing and/or taking out as many items as you wish. When you have done this, the cabinet will vanish, until summoned again.<b>\nRecharge: 100 silver</b>"
"text": "<b>Animal Speech (Adventure)</b>\nYou are able to communicate using the secret speech of animals. The text will tell you when you can cast this spell.\n<b>Recharge: 50 silver</b>\n\n<b>Armour of Heaven (Combat)</b>\nGain a +3 bonus to one party member's Armour which lasts until the end of this battle.\n<b>Recharge: 50 silver</b>\n\n<b>Ice Bolt (Combat)</b>\nYou conjure a great block of ice and hurl it at your foe with magical strength. Make an immediate attack with a Fighting score of 8 against any opponent.\n<b>Recharge: 50 silver</b>\n\n<b>Poison Stream (Combat)</b>\nA sickly green poison jets from your hands. Make two immediate attacks with a Fighting score of 5, against two different opponents.\n<b>Recharge: 50 silver</b>\n\n<b>Unfailing Strike (Combat)</b>\nA pillar of energy sizzles into a single foe. Choose an opponent to lose 3 Health.\n<b>Recharge: 50 silver</b>\n\n<b>Wolf Spirit (Adventure)</b>\nYou summon the spirit of the wolf to help guide you from danger in the natural world. Cast this spell when you fail a Survival check. You gain an additional 3 automatic successes for this check only.\n<b>Recharge: 75 silver</b>\n\n<b>Magic Cabinet (Adventure)</b>\nYou summon a magic cabinet made of purple wood. You can use this cabinet to access The Vault, storing and/or taking out as many items as you wish. When you have done this, the cabinet will vanish, until summoned again.\n<b>Recharge: 100 silver</b>"
},
{
"title": "Sea Combat",
Expand Down

0 comments on commit 2ce6a82

Please sign in to comment.