Merge PR #1310 into master
This commit is contained in:
@@ -753,7 +753,8 @@ void GfxRenderer::drawText(const int fontId, const int x, const int y, const cha
|
||||
const int yPos = y + getFontAscenderSize(fontId);
|
||||
int32_t xPosFP = fp4::fromPixel(x); // 12.4 fixed-point accumulator
|
||||
int lastBaseX = x;
|
||||
int lastBaseAdvanceFP = 0; // 12.4 fixed-point
|
||||
int lastBaseLeft = 0;
|
||||
int lastBaseWidth = 0;
|
||||
int lastBaseTop = 0;
|
||||
|
||||
// cannot draw a NULL / empty string
|
||||
@@ -772,24 +773,17 @@ void GfxRenderer::drawText(const int fontId, const int x, const int y, const cha
|
||||
return;
|
||||
}
|
||||
const auto& font = fontIt->second;
|
||||
constexpr int MIN_COMBINING_GAP_PX = 1;
|
||||
|
||||
uint32_t cp;
|
||||
uint32_t prevCp = 0;
|
||||
while ((cp = utf8NextCodepoint(reinterpret_cast<const uint8_t**>(&text)))) {
|
||||
if (utf8IsCombiningMark(cp)) {
|
||||
const EpdGlyph* combiningGlyph = font.getGlyph(cp, style);
|
||||
int raiseBy = 0;
|
||||
if (combiningGlyph) {
|
||||
const int currentGap = combiningGlyph->top - combiningGlyph->height - lastBaseTop;
|
||||
if (currentGap < MIN_COMBINING_GAP_PX) {
|
||||
raiseBy = MIN_COMBINING_GAP_PX - currentGap;
|
||||
}
|
||||
}
|
||||
|
||||
const int combiningX = lastBaseX + fp4::toPixel(lastBaseAdvanceFP / 2);
|
||||
const int combiningY = yPos - raiseBy;
|
||||
renderCharImpl<TextRotation::None>(*this, renderMode, font, cp, combiningX, combiningY, black, style);
|
||||
if (!combiningGlyph) continue;
|
||||
const int raiseBy = combiningMark::raiseAboveBase(combiningGlyph->top, combiningGlyph->height, lastBaseTop);
|
||||
const int combiningX = combiningMark::centerOver(lastBaseX, lastBaseLeft, lastBaseWidth, combiningGlyph->left,
|
||||
combiningGlyph->width);
|
||||
renderCharImpl<TextRotation::None>(*this, renderMode, font, cp, combiningX, yPos - raiseBy, black, style);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -800,7 +794,8 @@ void GfxRenderer::drawText(const int fontId, const int x, const int y, const cha
|
||||
lastBaseX = fp4::toPixel(xPosFP); // snap 12.4 fixed-point to nearest pixel
|
||||
const EpdGlyph* glyph = font.getGlyph(cp, style);
|
||||
|
||||
lastBaseAdvanceFP = glyph ? glyph->advanceX : 0;
|
||||
lastBaseLeft = glyph ? glyph->left : 0;
|
||||
lastBaseWidth = glyph ? glyph->width : 0;
|
||||
lastBaseTop = glyph ? glyph->top : 0;
|
||||
|
||||
renderCharImpl<TextRotation::None>(*this, renderMode, font, cp, lastBaseX, yPos, black, style);
|
||||
@@ -1812,25 +1807,20 @@ void GfxRenderer::drawTextRotated90CW(const int fontId, const int x, const int y
|
||||
|
||||
int32_t yPosFP = fp4::fromPixel(y); // 12.4 fixed-point accumulator
|
||||
int lastBaseY = y;
|
||||
int lastBaseAdvanceFP = 0; // 12.4 fixed-point
|
||||
int lastBaseLeft = 0;
|
||||
int lastBaseWidth = 0;
|
||||
int lastBaseTop = 0;
|
||||
constexpr int MIN_COMBINING_GAP_PX = 1;
|
||||
|
||||
uint32_t cp;
|
||||
uint32_t prevCp = 0;
|
||||
while ((cp = utf8NextCodepoint(reinterpret_cast<const uint8_t**>(&text)))) {
|
||||
if (utf8IsCombiningMark(cp)) {
|
||||
const EpdGlyph* combiningGlyph = font.getGlyph(cp, style);
|
||||
int raiseBy = 0;
|
||||
if (combiningGlyph) {
|
||||
const int currentGap = combiningGlyph->top - combiningGlyph->height - lastBaseTop;
|
||||
if (currentGap < MIN_COMBINING_GAP_PX) {
|
||||
raiseBy = MIN_COMBINING_GAP_PX - currentGap;
|
||||
}
|
||||
}
|
||||
|
||||
if (!combiningGlyph) continue;
|
||||
const int raiseBy = combiningMark::raiseAboveBase(combiningGlyph->top, combiningGlyph->height, lastBaseTop);
|
||||
const int combiningX = x - raiseBy;
|
||||
const int combiningY = lastBaseY - fp4::toPixel(lastBaseAdvanceFP / 2);
|
||||
const int combiningY = combiningMark::centerOverRotated90CW(lastBaseY, lastBaseLeft, lastBaseWidth,
|
||||
combiningGlyph->left, combiningGlyph->width);
|
||||
renderCharImpl<TextRotation::Rotated90CW>(*this, renderMode, font, cp, combiningX, combiningY, black, style);
|
||||
continue;
|
||||
}
|
||||
@@ -1843,7 +1833,8 @@ void GfxRenderer::drawTextRotated90CW(const int fontId, const int x, const int y
|
||||
lastBaseY = fp4::toPixel(yPosFP); // snap 12.4 fixed-point to nearest pixel
|
||||
const EpdGlyph* glyph = font.getGlyph(cp, style);
|
||||
|
||||
lastBaseAdvanceFP = glyph ? glyph->advanceX : 0; // 12.4 fixed-point
|
||||
lastBaseLeft = glyph ? glyph->left : 0;
|
||||
lastBaseWidth = glyph ? glyph->width : 0;
|
||||
lastBaseTop = glyph ? glyph->top : 0;
|
||||
|
||||
renderCharImpl<TextRotation::Rotated90CW>(*this, renderMode, font, cp, x, lastBaseY, black, style);
|
||||
|
||||
Reference in New Issue
Block a user