Basic framework for scaling text, unimplemented

This commit is contained in:
Doyle Thai 2016-07-15 18:34:23 +10:00
parent 0551f05e73
commit 12fbc1000e
3 changed files with 11 additions and 6 deletions

Binary file not shown.

View File

@ -266,7 +266,8 @@ const i32 asset_loadTTFont(AssetManager *assetManager, const char *filePath)
i32 startingGlyphIndex = 0;
i32 glyphsRemaining = numGlyphs;
i32 glyphsOnCurrRow = glyphsPerRow;
i32 glyphsOnCurrRow =
(glyphsPerRow < glyphsRemaining) ? glyphsPerRow : glyphsRemaining;
// TODO(doyle): We copy over the bitmap direct to the font sheet, should we
// align the baselines up so we don't need to do baseline adjusting at

View File

@ -23,12 +23,16 @@ void renderer_string(Renderer *const renderer, v4 cameraBounds,
f32 rotate, v4 color)
{
i32 strLen = common_strlen(string);
// TODO(doyle): Scale, not too important .. but rudimentary infrastructure
// laid out here
f32 scale = 1.0f;
// TODO(doyle): Slightly incorrect string length in pixels calculation,
// because we use the advance metric of each character for length not
// maximum character size in rendering
v2 rightAlignedP =
v2_add(pos, V2((CAST(f32) font->maxSize.w * CAST(f32) strLen),
CAST(f32) font->maxSize.h));
v2_add(pos, V2(scale *(CAST(f32) font->maxSize.w * CAST(f32) strLen),
scale * CAST(f32) font->maxSize.h));
v2 leftAlignedP = pos;
if ((leftAlignedP.x < cameraBounds.z && rightAlignedP.x >= cameraBounds.x) &&
(leftAlignedP.y < cameraBounds.y && rightAlignedP.y >= cameraBounds.w))
@ -49,12 +53,12 @@ void renderer_string(Renderer *const renderer, v4 cameraBounds,
i32 codepoint = string[i];
i32 relativeIndex = codepoint - font->codepointRange.x;
CharMetrics charMetric = font->charMetrics[relativeIndex];
pos.y = baseline - charMetric.offset.y;
pos.y = baseline - (scale * charMetric.offset.y);
const v4 charRectOnScreen = getRect(
pos, V2(CAST(f32) font->maxSize.w, CAST(f32) font->maxSize.h));
pos, V2(scale * CAST(f32) font->maxSize.w, scale * CAST(f32) font->maxSize.h));
pos.x += charMetric.advance;
pos.x += scale * charMetric.advance;
/* Get texture out */
v4 charTexRect = font->atlas->texRect[relativeIndex];