change textbounds to take a packer instead of batch
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
4b8975ee2a
commit
fec606a8c3
|
@ -150,7 +150,7 @@ WELLSPRINGAPI void Wellspring_StartTextBatch(
|
||||||
);
|
);
|
||||||
|
|
||||||
WELLSPRINGAPI uint8_t Wellspring_TextBounds(
|
WELLSPRINGAPI uint8_t Wellspring_TextBounds(
|
||||||
Wellspring_TextBatch *textBatch,
|
Wellspring_Packer* packer,
|
||||||
float x,
|
float x,
|
||||||
float y,
|
float y,
|
||||||
Wellspring_HorizontalAlignment horizontalAlignment,
|
Wellspring_HorizontalAlignment horizontalAlignment,
|
||||||
|
|
|
@ -384,8 +384,8 @@ static inline uint32_t IsWhitespace(uint32_t codepoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t Wellspring_TextBounds(
|
static uint8_t Wellspring_Internal_TextBounds(
|
||||||
Wellspring_TextBatch* textBatch,
|
Packer* packer,
|
||||||
float x,
|
float x,
|
||||||
float y,
|
float y,
|
||||||
Wellspring_HorizontalAlignment horizontalAlignment,
|
Wellspring_HorizontalAlignment horizontalAlignment,
|
||||||
|
@ -394,8 +394,6 @@ uint8_t Wellspring_TextBounds(
|
||||||
uint32_t strLengthInBytes,
|
uint32_t strLengthInBytes,
|
||||||
Wellspring_Rectangle *pRectangle
|
Wellspring_Rectangle *pRectangle
|
||||||
) {
|
) {
|
||||||
Batch* batch = (Batch*)textBatch;
|
|
||||||
Packer* myPacker = batch->currentPacker;
|
|
||||||
uint32_t decodeState = 0;
|
uint32_t decodeState = 0;
|
||||||
uint32_t codepoint;
|
uint32_t codepoint;
|
||||||
int32_t glyphIndex;
|
int32_t glyphIndex;
|
||||||
|
@ -412,7 +410,7 @@ uint8_t Wellspring_TextBounds(
|
||||||
float startX = x;
|
float startX = x;
|
||||||
float advance = 0;
|
float advance = 0;
|
||||||
|
|
||||||
y += Wellspring_INTERNAL_GetVerticalAlignOffset(myPacker->font, verticalAlignment, myPacker->scale);
|
y += Wellspring_INTERNAL_GetVerticalAlignOffset(packer->font, verticalAlignment, packer->scale);
|
||||||
|
|
||||||
for (i = 0; i < strLengthInBytes; i += 1)
|
for (i = 0; i < strLengthInBytes; i += 1)
|
||||||
{
|
{
|
||||||
|
@ -430,24 +428,24 @@ uint8_t Wellspring_TextBounds(
|
||||||
if (IsWhitespace(codepoint))
|
if (IsWhitespace(codepoint))
|
||||||
{
|
{
|
||||||
int32_t ws_adv, ws_bearing;
|
int32_t ws_adv, ws_bearing;
|
||||||
stbtt_GetCodepointHMetrics(&myPacker->font->fontInfo, codepoint, &ws_adv, &ws_bearing);
|
stbtt_GetCodepointHMetrics(&packer->font->fontInfo, codepoint, &ws_adv, &ws_bearing);
|
||||||
x += myPacker->scale * ws_adv;
|
x += packer->scale * ws_adv;
|
||||||
maxX += myPacker->scale * ws_adv;
|
maxX += packer->scale * ws_adv;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
rangeData = NULL;
|
rangeData = NULL;
|
||||||
|
|
||||||
/* Find the packed char data */
|
/* Find the packed char data */
|
||||||
for (j = 0; j < myPacker->rangeCount; j += 1)
|
for (j = 0; j < packer->rangeCount; j += 1)
|
||||||
{
|
{
|
||||||
if (
|
if (
|
||||||
codepoint >= myPacker->ranges[j].firstCodepoint &&
|
codepoint >= packer->ranges[j].firstCodepoint &&
|
||||||
codepoint < myPacker->ranges[j].firstCodepoint + myPacker->ranges[j].charCount
|
codepoint < packer->ranges[j].firstCodepoint + packer->ranges[j].charCount
|
||||||
) {
|
) {
|
||||||
rangeData = myPacker->ranges[j].data;
|
rangeData = packer->ranges[j].data;
|
||||||
rangeIndex = codepoint - myPacker->ranges[j].firstCodepoint;
|
rangeIndex = codepoint - packer->ranges[j].firstCodepoint;
|
||||||
rangeFontSize = myPacker->ranges[j].fontSize;
|
rangeFontSize = packer->ranges[j].fontSize;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -458,17 +456,17 @@ uint8_t Wellspring_TextBounds(
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
glyphIndex = stbtt_FindGlyphIndex(&myPacker->font->fontInfo, codepoint);
|
glyphIndex = stbtt_FindGlyphIndex(&packer->font->fontInfo, codepoint);
|
||||||
|
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
{
|
{
|
||||||
x += myPacker->scale * stbtt_GetGlyphKernAdvance(&myPacker->font->fontInfo, previousGlyphIndex, glyphIndex);
|
x += packer->scale * stbtt_GetGlyphKernAdvance(&packer->font->fontInfo, previousGlyphIndex, glyphIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
stbtt_GetPackedQuad(
|
stbtt_GetPackedQuad(
|
||||||
rangeData,
|
rangeData,
|
||||||
myPacker->width,
|
packer->width,
|
||||||
myPacker->height,
|
packer->height,
|
||||||
rangeIndex,
|
rangeIndex,
|
||||||
&x,
|
&x,
|
||||||
&y,
|
&y,
|
||||||
|
@ -505,6 +503,28 @@ uint8_t Wellspring_TextBounds(
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t Wellspring_TextBounds(
|
||||||
|
Wellspring_Packer* packer,
|
||||||
|
float x,
|
||||||
|
float y,
|
||||||
|
Wellspring_HorizontalAlignment horizontalAlignment,
|
||||||
|
Wellspring_VerticalAlignment verticalAlignment,
|
||||||
|
const uint8_t* strBytes,
|
||||||
|
uint32_t strLengthInBytes,
|
||||||
|
Wellspring_Rectangle* pRectangle
|
||||||
|
) {
|
||||||
|
return Wellspring_Internal_TextBounds(
|
||||||
|
(Packer*) packer,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
horizontalAlignment,
|
||||||
|
verticalAlignment,
|
||||||
|
strBytes,
|
||||||
|
strLengthInBytes,
|
||||||
|
pRectangle
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t Wellspring_Draw(
|
uint8_t Wellspring_Draw(
|
||||||
Wellspring_TextBatch *textBatch,
|
Wellspring_TextBatch *textBatch,
|
||||||
float x,
|
float x,
|
||||||
|
@ -536,7 +556,7 @@ uint8_t Wellspring_Draw(
|
||||||
/* FIXME: If we horizontally align, we have to decode and process glyphs twice, very inefficient. */
|
/* FIXME: If we horizontally align, we have to decode and process glyphs twice, very inefficient. */
|
||||||
if (horizontalAlignment == WELLSPRING_HORIZONTALALIGNMENT_RIGHT)
|
if (horizontalAlignment == WELLSPRING_HORIZONTALALIGNMENT_RIGHT)
|
||||||
{
|
{
|
||||||
if (!Wellspring_TextBounds(textBatch, x, y, horizontalAlignment, verticalAlignment, strBytes, strLengthInBytes, &bounds))
|
if (!Wellspring_Internal_TextBounds(myPacker, x, y, horizontalAlignment, verticalAlignment, strBytes, strLengthInBytes, &bounds))
|
||||||
{
|
{
|
||||||
/* Something went wrong while calculating bounds. */
|
/* Something went wrong while calculating bounds. */
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -546,7 +566,7 @@ uint8_t Wellspring_Draw(
|
||||||
}
|
}
|
||||||
else if (horizontalAlignment == WELLSPRING_HORIZONTALALIGNMENT_CENTER)
|
else if (horizontalAlignment == WELLSPRING_HORIZONTALALIGNMENT_CENTER)
|
||||||
{
|
{
|
||||||
if (!Wellspring_TextBounds(textBatch, x, y, horizontalAlignment, verticalAlignment, strBytes, strLengthInBytes, &bounds))
|
if (!Wellspring_Internal_TextBounds(myPacker, x, y, horizontalAlignment, verticalAlignment, strBytes, strLengthInBytes, &bounds))
|
||||||
{
|
{
|
||||||
/* Something went wrong while calculating bounds. */
|
/* Something went wrong while calculating bounds. */
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue