app_server/AGGTextRenderer: Improve code quality, remove duplicates
Change-Id: Ia1d6ec8ad836dcd08f36841cbc16b5a609fd7aff Reviewed-on: https://review.haiku-os.org/c/haiku/+/8861 Reviewed-by: Máximo Castañeda <[email protected]> Tested-by: Commit checker robot <[email protected]> Haiku-Format: Haiku-format Bot <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
7aa3dc423e
commit
ef67cb1ace
@@ -119,7 +119,6 @@ typedef agg::conv_transform<FontCacheEntry::ContourConverter, Transformable>
|
|||||||
class AGGTextRenderer::StringRenderer {
|
class AGGTextRenderer::StringRenderer {
|
||||||
public:
|
public:
|
||||||
StringRenderer(const IntRect& clippingFrame, bool dryRun,
|
StringRenderer(const IntRect& clippingFrame, bool dryRun,
|
||||||
bool subpixelAntiAliased, bool underscore, bool strikeout,
|
|
||||||
FontCacheEntry::TransformedOutline& transformedGlyph,
|
FontCacheEntry::TransformedOutline& transformedGlyph,
|
||||||
FontCacheEntry::TransformedContourOutline& transformedContour,
|
FontCacheEntry::TransformedContourOutline& transformedContour,
|
||||||
const Transformable& transform,
|
const Transformable& transform,
|
||||||
@@ -131,10 +130,7 @@ public:
|
|||||||
fTransformOffset(transformOffset),
|
fTransformOffset(transformOffset),
|
||||||
fClippingFrame(clippingFrame),
|
fClippingFrame(clippingFrame),
|
||||||
fDryRun(dryRun),
|
fDryRun(dryRun),
|
||||||
fSubpixelAntiAliased(subpixelAntiAliased),
|
|
||||||
fVector(false),
|
fVector(false),
|
||||||
fUnderscore(underscore),
|
|
||||||
fStrikeout(strikeout),
|
|
||||||
fBounds(INT32_MAX, INT32_MAX, INT32_MIN, INT32_MIN),
|
fBounds(INT32_MAX, INT32_MAX, INT32_MIN, INT32_MIN),
|
||||||
fNextCharPos(nextCharPos),
|
fNextCharPos(nextCharPos),
|
||||||
|
|
||||||
@@ -143,6 +139,7 @@ public:
|
|||||||
|
|
||||||
fRenderer(renderer)
|
fRenderer(renderer)
|
||||||
{
|
{
|
||||||
|
fSubpixelAntiAliased = gSubpixelAntialiasing && fRenderer.Antialiasing();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NeedsVector()
|
bool NeedsVector()
|
||||||
@@ -171,56 +168,14 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fUnderscore && !fDryRun) {
|
if (!fDryRun) {
|
||||||
agg::path_storage path;
|
if ((fRenderer.fFont.Face() & B_UNDERSCORE_FACE) != 0)
|
||||||
IntRect bounds = fBounds;
|
_DrawHorizontalLine(y + 2);
|
||||||
bounds.bottom = (int)y;
|
|
||||||
bounds.OffsetBy(fTransformOffset);
|
|
||||||
path.move_to(bounds.left + 0.5, bounds.bottom + 2.5);
|
|
||||||
path.line_to(bounds.right + 0.5, bounds.bottom + 2.5);
|
|
||||||
path.close_polygon();
|
|
||||||
agg::conv_stroke<agg::path_storage> pathStorage(path);
|
|
||||||
pathStorage.width(fRenderer.fFont.Size() / 12.0f);
|
|
||||||
if (fRenderer.fMaskedScanline != NULL) {
|
|
||||||
fRenderer.fRasterizer.add_path(pathStorage);
|
|
||||||
agg::render_scanlines(fRenderer.fRasterizer,
|
|
||||||
*fRenderer.fMaskedScanline, fRenderer.fSolidRenderer);
|
|
||||||
} else if (fSubpixelAntiAliased) {
|
|
||||||
fRenderer.fSubpixRasterizer.add_path(pathStorage);
|
|
||||||
agg::render_scanlines(fRenderer.fSubpixRasterizer,
|
|
||||||
fRenderer.fSubpixScanline, fRenderer.fSubpixRenderer);
|
|
||||||
} else {
|
|
||||||
fRenderer.fRasterizer.add_path(pathStorage);
|
|
||||||
agg::render_scanlines(fRenderer.fRasterizer,
|
|
||||||
fRenderer.fScanline, fRenderer.fSolidRenderer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fStrikeout && !fDryRun) {
|
if ((fRenderer.fFont.Face() & B_STRIKEOUT_FACE) != 0) {
|
||||||
agg::path_storage path;
|
font_height fontHeight;
|
||||||
font_height fontHeight;
|
fRenderer.fFont.GetHeight(fontHeight);
|
||||||
IntRect bounds = fBounds;
|
_DrawHorizontalLine(y - (fontHeight.ascent + fontHeight.descent) / 4);
|
||||||
fRenderer.fFont.GetHeight(fontHeight);
|
|
||||||
float totalFontHeight = fontHeight.ascent + fontHeight.descent;
|
|
||||||
bounds.bottom = (int)y;
|
|
||||||
bounds.OffsetBy(fTransformOffset);
|
|
||||||
path.move_to(bounds.left + 0.5, round(bounds.bottom - totalFontHeight * 0.25) + 0.5);
|
|
||||||
path.line_to(bounds.right + 0.5, round(bounds.bottom - totalFontHeight * 0.25) + 0.5);
|
|
||||||
path.close_polygon();
|
|
||||||
agg::conv_stroke<agg::path_storage> pathStorage(path);
|
|
||||||
pathStorage.width(fRenderer.fFont.Size() / 12.0f);
|
|
||||||
if (fRenderer.fMaskedScanline != NULL) {
|
|
||||||
fRenderer.fRasterizer.add_path(pathStorage);
|
|
||||||
agg::render_scanlines(fRenderer.fRasterizer,
|
|
||||||
*fRenderer.fMaskedScanline, fRenderer.fSolidRenderer);
|
|
||||||
} else if (fSubpixelAntiAliased) {
|
|
||||||
fRenderer.fSubpixRasterizer.add_path(pathStorage);
|
|
||||||
agg::render_scanlines(fRenderer.fSubpixRasterizer,
|
|
||||||
fRenderer.fSubpixScanline, fRenderer.fSubpixRenderer);
|
|
||||||
} else {
|
|
||||||
fRenderer.fRasterizer.add_path(pathStorage);
|
|
||||||
agg::render_scanlines(fRenderer.fRasterizer,
|
|
||||||
fRenderer.fScanline, fRenderer.fSolidRenderer);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,6 +323,33 @@ public:
|
|||||||
return fBounds;
|
return fBounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void _DrawHorizontalLine(float y)
|
||||||
|
{
|
||||||
|
agg::path_storage path;
|
||||||
|
IntRect bounds = fBounds;
|
||||||
|
bounds.bottom = (int)y;
|
||||||
|
bounds.OffsetBy(fTransformOffset);
|
||||||
|
path.move_to(bounds.left + 0.5, bounds.bottom + 0.5);
|
||||||
|
path.line_to(bounds.right + 0.5, bounds.bottom + 0.5);
|
||||||
|
path.close_polygon();
|
||||||
|
agg::conv_stroke<agg::path_storage> pathStorage(path);
|
||||||
|
pathStorage.width(fRenderer.fFont.Size() / 12.0f);
|
||||||
|
if (fRenderer.fMaskedScanline != NULL) {
|
||||||
|
fRenderer.fRasterizer.add_path(pathStorage);
|
||||||
|
agg::render_scanlines(fRenderer.fRasterizer,
|
||||||
|
*fRenderer.fMaskedScanline, fRenderer.fSolidRenderer);
|
||||||
|
} else if (fSubpixelAntiAliased) {
|
||||||
|
fRenderer.fSubpixRasterizer.add_path(pathStorage);
|
||||||
|
agg::render_scanlines(fRenderer.fSubpixRasterizer,
|
||||||
|
fRenderer.fSubpixScanline, fRenderer.fSubpixRenderer);
|
||||||
|
} else {
|
||||||
|
fRenderer.fRasterizer.add_path(pathStorage);
|
||||||
|
agg::render_scanlines(fRenderer.fRasterizer,
|
||||||
|
fRenderer.fScanline, fRenderer.fSolidRenderer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const Transformable& fTransform;
|
const Transformable& fTransform;
|
||||||
const BPoint& fTransformOffset;
|
const BPoint& fTransformOffset;
|
||||||
@@ -375,8 +357,6 @@ private:
|
|||||||
bool fDryRun;
|
bool fDryRun;
|
||||||
bool fSubpixelAntiAliased;
|
bool fSubpixelAntiAliased;
|
||||||
bool fVector;
|
bool fVector;
|
||||||
bool fUnderscore;
|
|
||||||
bool fStrikeout;
|
|
||||||
IntRect fBounds;
|
IntRect fBounds;
|
||||||
BPoint* fNextCharPos;
|
BPoint* fNextCharPos;
|
||||||
|
|
||||||
@@ -413,12 +393,8 @@ AGGTextRenderer::RenderString(const char* string, uint32 length,
|
|||||||
transform.Transform(&transformOffset);
|
transform.Transform(&transformOffset);
|
||||||
IntRect clippingIntFrame(clippingFrame);
|
IntRect clippingIntFrame(clippingFrame);
|
||||||
|
|
||||||
bool underscore = (fFont.Face() & B_UNDERSCORE_FACE) != 0;
|
StringRenderer renderer(clippingIntFrame, dryRun, transformedOutline, transformedContourOutline,
|
||||||
bool strikeout = (fFont.Face() & B_STRIKEOUT_FACE) != 0;
|
transform, transformOffset, nextCharPos, *this);
|
||||||
|
|
||||||
StringRenderer renderer(clippingIntFrame, dryRun, gSubpixelAntialiasing && fAntialias,
|
|
||||||
underscore, strikeout, transformedOutline, transformedContourOutline, transform,
|
|
||||||
transformOffset, nextCharPos, *this);
|
|
||||||
|
|
||||||
GlyphLayoutEngine::LayoutGlyphs(renderer, fFont, string, length, INT32_MAX,
|
GlyphLayoutEngine::LayoutGlyphs(renderer, fFont, string, length, INT32_MAX,
|
||||||
delta, fFont.Spacing(), NULL, cacheReference);
|
delta, fFont.Spacing(), NULL, cacheReference);
|
||||||
@@ -452,12 +428,8 @@ AGGTextRenderer::RenderString(const char* string, uint32 length,
|
|||||||
transform.Transform(&transformOffset);
|
transform.Transform(&transformOffset);
|
||||||
IntRect clippingIntFrame(clippingFrame);
|
IntRect clippingIntFrame(clippingFrame);
|
||||||
|
|
||||||
bool underscore = (fFont.Face() & B_UNDERSCORE_FACE) != 0;
|
StringRenderer renderer(clippingIntFrame, dryRun, transformedOutline, transformedContourOutline,
|
||||||
bool strikeout = (fFont.Face() & B_STRIKEOUT_FACE) != 0;
|
transform, transformOffset, nextCharPos, *this);
|
||||||
|
|
||||||
StringRenderer renderer(clippingIntFrame, dryRun, gSubpixelAntialiasing && fAntialias,
|
|
||||||
underscore, strikeout, transformedOutline, transformedContourOutline, transform,
|
|
||||||
transformOffset, nextCharPos, *this);
|
|
||||||
|
|
||||||
GlyphLayoutEngine::LayoutGlyphs(renderer, fFont, string, length, INT32_MAX,
|
GlyphLayoutEngine::LayoutGlyphs(renderer, fFont, string, length, INT32_MAX,
|
||||||
NULL, fFont.Spacing(), offsets, cacheReference);
|
NULL, fFont.Spacing(), offsets, cacheReference);
|
||||||
|
|||||||
Reference in New Issue
Block a user