From 10f6ed940bffa4153ff5511897bcc823b1f2d792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Mon, 18 Dec 2006 05:22:13 +0000 Subject: [PATCH] * implemented "false bold" for text rendering. It is a new property of BFont. You can BFont::SetFalseBoldWidth(float) a width on a BFont object, and it will cause the glyph shapes to be run through an AGG "contour converter" so that they become thicker or thinner. IIRC, this is commonly referred to as "false bold". The "width" value is the distance in pixels that the new glyph outline will be offset from the original outline. It would be nice if someone could look at my change to View.h with regards to the B_FONT_ALL flag. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19547 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/interface/Font.h | 5 +- headers/os/interface/View.h | 3 +- src/kits/interface/Font.cpp | 54 +++++++++--- src/kits/interface/View.cpp | 21 +++-- src/servers/app/DrawState.cpp | 7 ++ src/servers/app/ServerApp.cpp | 84 +++++++++++-------- src/servers/app/ServerFont.cpp | 18 ++-- src/servers/app/ServerFont.h | 10 ++- .../Painter/font_support/AGGTextRenderer.cpp | 29 ++++--- 9 files changed, 149 insertions(+), 82 deletions(-) diff --git a/headers/os/interface/Font.h b/headers/os/interface/Font.h index 796f1677e9..42bcda5afe 100644 --- a/headers/os/interface/Font.h +++ b/headers/os/interface/Font.h @@ -153,6 +153,7 @@ class BFont { void SetSize(float size); void SetShear(float shear); void SetRotation(float rotation); + void SetFalseBoldWidth(float width); void SetSpacing(uint8 spacing); void SetEncoding(uint8 encoding); void SetFace(uint16 face); @@ -164,6 +165,7 @@ class BFont { float Size() const; float Shear() const; float Rotation() const; + float FalseBoldWidth() const; uint8 Spacing() const; uint8 Encoding() const; uint16 Face() const; @@ -239,13 +241,14 @@ class BFont { float fSize; float fShear; float fRotation; + float fFalseBoldWidth; uint8 fSpacing; uint8 fEncoding; uint16 fFace; uint32 fFlags; mutable font_height fHeight; mutable uint32 fExtraFlags; - uint32 _reserved[2]; + uint32 _reserved[1]; void _GetExtraFlags() const; void _GetBoundingBoxes(const char charArray[], diff --git a/headers/os/interface/View.h b/headers/os/interface/View.h index e7c8a62333..4e01a4dc9d 100644 --- a/headers/os/interface/View.h +++ b/headers/os/interface/View.h @@ -61,7 +61,8 @@ enum { B_FONT_ENCODING = 0x00000020, B_FONT_FACE = 0x00000040, B_FONT_FLAGS = 0x00000080, - B_FONT_ALL = 0x000000FF + B_FONT_FALSE_BOLD_WIDTH = 0x00000100, + B_FONT_ALL = 0x000001FF }; // view flags diff --git a/src/kits/interface/Font.cpp b/src/kits/interface/Font.cpp index 19eca16f3a..21f8a854e9 100644 --- a/src/kits/interface/Font.cpp +++ b/src/kits/interface/Font.cpp @@ -6,6 +6,7 @@ * DarkWyrm * Jérôme Duval, jerome.duval@free.fr * Axel Dörfler, axeld@pinc-software.de + * Stephan Aßmus */ @@ -508,6 +509,7 @@ BFont::BFont() fSize(10.0), fShear(90.0), fRotation(0.0), + fFalseBoldWidth(0.0), fSpacing(0), fEncoding(0), fFace(0), @@ -583,10 +585,11 @@ BFont::SetFamilyAndStyle(const font_family family, const font_style style) void BFont::SetFamilyAndStyle(uint32 fontcode) { - // R5 has a bug here: the face is not updated even though the IDs are set. This - // is a problem because the face flag includes Regular/Bold/Italic information in - // addition to stuff like underlining and strikethrough. As a result, this will - // need a trip to the server and, thus, be slower than R5's in order to be correct + // R5 has a bug here: the face is not updated even though the IDs are set. + // This is a problem because the face flag includes Regular/Bold/Italic + // information in addition to stuff like underlining and strikethrough. + // As a result, this will need a trip to the server and, thus, be slower + // than R5's in order to be correct uint16 family, style; style = fontcode & 0xFFFF; @@ -618,9 +621,10 @@ BFont::SetFamilyAndStyle(uint32 fontcode) \param face Font face to set. \return B_ERROR if family does not exists or face is an invalid value. - To comply with the BeBook, this function will only set valid values - i.e. passing a - nonexistent family will cause only the face to be set. Additionally, if a particular - face does not exist in a family, the closest match will be chosen. + To comply with the BeBook, this function will only set valid values - i.e. + passing a nonexistent family will cause only the face to be set. + Additionally, if a particular face does not exist in a family, the closest + match will be chosen. */ status_t @@ -672,6 +676,13 @@ BFont::SetRotation(float rotation) } +void +BFont::SetFalseBoldWidth(float width) +{ + fFalseBoldWidth = width; +} + + void BFont::SetSpacing(uint8 spacing) { @@ -766,6 +777,13 @@ BFont::Rotation() const } +float +BFont::FalseBoldWidth() const +{ + return fFalseBoldWidth; +} + + uint8 BFont::Spacing() const { @@ -811,10 +829,11 @@ BFont::IsFixed() const /*! - \brief Returns true if the font is fixed-width and contains both full and half-width characters + \brief Returns true if the font is fixed-width and contains both full + and half-width characters - This was left unimplemented as of R5. It was a way to work with both Kanji and Roman - characters in the same fixed-width font. + This was left unimplemented as of R5. It was a way to work with both + Kanji and Roman characters in the same fixed-width font. */ bool @@ -918,7 +937,8 @@ void BFont::TruncateString(BString *inOut, uint32 mode, float width) const { // NOTE: Careful, we cannot directly use "inOut->String()" as result - // array, because the string length increases by 3 bytes in the worst case scenario. + // array, because the string length increases by 3 bytes in the worst + // case scenario. const char *string = inOut->String(); GetTruncatedStrings(&string, 1, mode, width, inOut); } @@ -935,7 +955,8 @@ BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings, truncatedStrings[i] = new char[strlen(stringArray[i]) + 3]; } - GetTruncatedStrings(stringArray, numStrings, mode, width, truncatedStrings); + GetTruncatedStrings(stringArray, numStrings, mode, width, + truncatedStrings); // copy the strings into the BString array and free each one for (int32 i = 0; i < numStrings; i++) { @@ -963,7 +984,8 @@ BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings, GetEscapements(stringArray[i], numChars, NULL, escapementArray); truncate_string(stringArray[i], mode, width, resultArray[i], - escapementArray, fSize, ellipsisWidth, length, numChars); + escapementArray, fSize, ellipsisWidth, length, + numChars); delete[] escapementArray; } @@ -1199,6 +1221,7 @@ BFont::_GetBoundingBoxes(const char charArray[], int32 numChars, font_metric_mod link.Attach(fSize); link.Attach(fRotation); link.Attach(fShear); + link.Attach(fFalseBoldWidth); link.Attach(fSpacing); link.Attach(fFlags); @@ -1241,6 +1264,7 @@ BFont::GetBoundingBoxesForStrings(const char *stringArray[], int32 numStrings, link.Attach(fSize); link.Attach(fRotation); link.Attach(fShear); + link.Attach(fFalseBoldWidth); link.Attach(fSpacing); link.Attach(fFlags); link.Attach(mode); @@ -1284,6 +1308,7 @@ BFont::GetGlyphShapes(const char charArray[], int32 numChars, BShape *glyphShape link.Attach(fSize); link.Attach(fShear); link.Attach(fRotation); + link.Attach(fFalseBoldWidth); link.Attach(fFlags); link.Attach(numChars); @@ -1334,6 +1359,7 @@ BFont::operator=(const BFont &font) fSize = font.fSize; fShear = font.fShear; fRotation = font.fRotation; + fFalseBoldWidth = font.fFalseBoldWidth; fSpacing = font.fSpacing; fEncoding = font.fEncoding; fFace = font.fFace; @@ -1351,6 +1377,7 @@ BFont::operator==(const BFont &font) const && fSize == font.fSize && fShear == font.fShear && fRotation == font.fRotation + && fFalseBoldWidth == font.fFalseBoldWidth && fSpacing == font.fSpacing && fEncoding == font.fEncoding && fFace == font.fFace; @@ -1365,6 +1392,7 @@ BFont::operator!=(const BFont &font) const || fSize != font.fSize || fShear != font.fShear || fRotation != font.fRotation + || fFalseBoldWidth != font.fFalseBoldWidth || fSpacing != font.fSpacing || fEncoding != font.fEncoding || fFace != font.fFace; diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index 41480cc47f..1069f653f0 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -158,14 +158,10 @@ ViewState::UpdateServerFontState(BPrivate::PortLink &link) { link.StartMessage(AS_LAYER_SET_FONT_STATE); link.Attach(font_flags); + // always present - // always present. - if (font_flags & B_FONT_FAMILY_AND_STYLE) { - uint32 fontID; - fontID = font.FamilyAndStyle(); - - link.Attach(fontID); - } + if (font_flags & B_FONT_FAMILY_AND_STYLE) + link.Attach(font.FamilyAndStyle()); if (font_flags & B_FONT_SIZE) link.Attach(font.Size()); @@ -176,6 +172,9 @@ ViewState::UpdateServerFontState(BPrivate::PortLink &link) if (font_flags & B_FONT_ROTATION) link.Attach(font.Rotation()); + if (font_flags & B_FONT_FALSE_BOLD_WIDTH) + link.Attach(font.FalseBoldWidth()); + if (font_flags & B_FONT_SPACING) link.Attach(font.Spacing()); @@ -244,6 +243,7 @@ ViewState::UpdateFrom(BPrivate::PortLink &link) float size; float shear; float rotation; + float falseBoldeWidth; uint8 spacing; uint8 encoding; uint16 face; @@ -254,6 +254,7 @@ ViewState::UpdateFrom(BPrivate::PortLink &link) link.Read(&size); link.Read(&shear); link.Read(&rotation); + link.Read(&falseBoldeWidth); link.Read((int8 *)&spacing); link.Read((int8 *)&encoding); link.Read((int16 *)&face); @@ -264,6 +265,7 @@ ViewState::UpdateFrom(BPrivate::PortLink &link) font.SetSize(size); font.SetShear(shear); font.SetRotation(rotation); + font.SetFalseBoldWidth(falseBoldeWidth); font.SetSpacing(spacing); font.SetEncoding(encoding); font.SetFace(face); @@ -2102,6 +2104,9 @@ BView::SetFont(const BFont* font, uint32 mask) if (mask & B_FONT_ROTATION) fState->font.SetRotation(font->Rotation()); + if (mask & B_FONT_FALSE_BOLD_WIDTH) + fState->font.SetFalseBoldWidth(font->FalseBoldWidth()); + if (mask & B_FONT_SPACING) fState->font.SetSpacing(font->Spacing()); @@ -2115,7 +2120,7 @@ BView::SetFont(const BFont* font, uint32 mask) fState->font.SetFlags(font->Flags()); } - fState->font_flags = mask; + fState->font_flags |= mask; if (fOwner) { check_lock(); diff --git a/src/servers/app/DrawState.cpp b/src/servers/app/DrawState.cpp index d3c04a482a..8ada423602 100644 --- a/src/servers/app/DrawState.cpp +++ b/src/servers/app/DrawState.cpp @@ -158,6 +158,12 @@ DrawState::ReadFontFromLink(BPrivate::LinkReceiver& link) fFont.SetRotation(rotation); } + if (mask & B_FONT_FALSE_BOLD_WIDTH) { + float falseBoldWidth; + link.Read(&falseBoldWidth); + fFont.SetFalseBoldWidth(falseBoldWidth); + } + if (mask & B_FONT_SPACING) { uint8 spacing; link.Read(&spacing); @@ -237,6 +243,7 @@ DrawState::WriteToLink(BPrivate::LinkSender& link) const link.Attach(fFont.Size()); link.Attach(fFont.Shear()); link.Attach(fFont.Rotation()); + link.Attach(fFont.FalseBoldWidth()); link.Attach(fFont.Spacing()); link.Attach(fFont.Encoding()); link.Attach(fFont.Face()); diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index b7f928ca68..d454cbe7f4 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -53,6 +53,7 @@ #include #include +#include #include #include #include @@ -1346,6 +1347,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) int32 lengthArray[numStrings]; char *stringArray[numStrings]; for (int32 i = 0; i < numStrings; i++) { +// TODO: who allocates the strings?!? If the link does it then we are leaking +// everywhere else!! link.ReadString(&stringArray[i], (size_t *)&lengthArray[i]); } @@ -1504,6 +1507,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) // 3) float - point size // 4) float - shear // 5) float - rotation + // 6) float - false bold width // 6) uint32 - flags // 7) int32 - numChars // 8) int32 - numBytes @@ -1515,20 +1519,21 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) uint16 familyID, styleID; uint32 flags; - float size, shear, rotation; + float size, shear, rotation, falseBoldWidth; link.Read(&familyID); link.Read(&styleID); link.Read(&size); link.Read(&shear); link.Read(&rotation); + link.Read(&falseBoldWidth); link.Read(&flags); int32 numChars, numBytes; link.Read(&numChars); link.Read(&numBytes); - char *charArray = new char[numBytes]; + char* charArray = new (nothrow) char[numBytes]; link.Read(charArray, numBytes); ServerFont font; @@ -1537,9 +1542,10 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) font.SetSize(size); font.SetShear(shear); font.SetRotation(rotation); + font.SetFalseBoldWidth(falseBoldWidth); font.SetFlags(flags); - BShape **shapes = new BShape *[numChars]; + BShape** shapes = new (nothrow) BShape*[numChars]; status = font.GetGlyphShapes(charArray, numChars, shapes); if (status == B_OK) { fLink.StartMessage(B_OK); @@ -1547,10 +1553,10 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) fLink.AttachShape(*shapes[i]); delete shapes[i]; } - - delete[] shapes; } else fLink.StartMessage(status); + + delete[] shapes; } else fLink.StartMessage(status); @@ -1575,7 +1581,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) int32 numChars, numBytes; link.Read(&numChars); link.Read(&numBytes); - char* charArray = new char[numBytes]; + char* charArray = new (nothrow) char[numBytes]; link.Read(charArray, numBytes); ServerFont font; @@ -1614,7 +1620,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) uint32 numBytes; link.Read(&numBytes); - char* charArray = new char[numBytes]; + char* charArray = new (nothrow) char[numBytes]; link.Read(charArray, numBytes); ServerFont font; @@ -1676,7 +1682,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) uint32 numBytes; link.Read(&numBytes); - char *charArray = new char[numBytes]; + char *charArray = new (nothrow) char[numBytes]; link.Read(charArray, numBytes); ServerFont font; @@ -1687,10 +1693,10 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) font.SetRotation(rotation); font.SetFlags(flags); - BPoint *escapements = new BPoint[numChars]; + BPoint *escapements = new (nothrow) BPoint[numChars]; BPoint *offsets = NULL; if (wantsOffsets) - offsets = new BPoint[numChars]; + offsets = new (nothrow) BPoint[numChars]; status = font.GetEscapements(charArray, numChars, delta, escapements, offsets); @@ -1700,16 +1706,16 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) for (int32 i = 0; i < numChars; i++) fLink.Attach(escapements[i]); - delete[] escapements; - if (wantsOffsets) { for (int32 i = 0; i < numChars; i++) fLink.Attach(offsets[i]); - - delete[] offsets; } } else fLink.StartMessage(status); + + delete[] escapements; + delete[] offsets; + } else fLink.StartMessage(status); @@ -1759,10 +1765,10 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) uint32 numBytes; link.Read(&numBytes); - char* charArray = new char[numBytes]; + char* charArray = new (nothrow) char[numBytes]; link.Read(charArray, numBytes); - float* escapements = new float[numChars]; + float* escapements = new (nothrow) float[numChars]; // figure out escapements @@ -1801,24 +1807,25 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) // 3) float - point size // 4) float - rotation // 5) float - shear - // 6) uint8 - spacing - // 7) uint32 - flags + // 6) float - false bold width + // 7) uint8 - spacing + // 8) uint32 - flags - // 8) font_metric_mode - mode - // 9) bool - string escapement + // 9) font_metric_mode - mode + // 10) bool - string escapement - // 10) escapement_delta - additional delta + // 11) escapement_delta - additional delta - // 11) int32 - numChars - // 12) int32 - numBytes - // 13) char - the char buffer with size numBytes + // 12) int32 - numChars + // 13) int32 - numBytes + // 14) char - the char buffer with size numBytes // Returns: // 1) BRect - rects with numChar entries uint16 famid, styid; uint32 flags; - float ptsize, rotation, shear; + float ptsize, rotation, shear, falseBoldWidth; uint8 spacing; font_metric_mode mode; bool string_escapement; @@ -1828,6 +1835,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) link.Read(&ptsize); link.Read(&rotation); link.Read(&shear); + link.Read(&falseBoldWidth); link.Read(&spacing); link.Read(&flags); link.Read(&mode); @@ -1842,7 +1850,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) uint32 numBytes; link.Read(&numBytes); - char *charArray = new char[numBytes]; + char *charArray = new (nothrow) char[numBytes]; link.Read(charArray, numBytes); BRect rectArray[numChars]; @@ -1854,6 +1862,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) font.SetSize(ptsize); font.SetRotation(rotation); font.SetShear(shear); + font.SetFalseBoldWidth(falseBoldWidth); font.SetSpacing(spacing); font.SetFlags(flags); @@ -1882,22 +1891,23 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) // 3) float - point size // 4) float - rotation // 5) float - shear - // 6) uint8 - spacing - // 7) uint32 - flags + // 6) float - false bold width + // 7) uint8 - spacing + // 8) uint32 - flags - // 8) font_metric_mode - mode - // 9) int32 numStrings + // 9) font_metric_mode - mode + // 10) int32 numStrings - // 10) escapement_delta - additional delta (numStrings times) - // 11) int32 string length to measure (numStrings times) - // 12) string - string (numStrings times) + // 11) escapement_delta - additional delta (numStrings times) + // 12) int32 string length to measure (numStrings times) + // 13) string - string (numStrings times) // Returns: // 1) BRect - rects with numStrings entries uint16 famid, styid; uint32 flags; - float ptsize, rotation, shear; + float ptsize, rotation, shear, falseBoldWidth; uint8 spacing; font_metric_mode mode; @@ -1906,6 +1916,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) link.Read(&ptsize); link.Read(&rotation); link.Read(&shear); + link.Read(&falseBoldWidth); link.Read(&spacing); link.Read(&flags); link.Read(&mode); @@ -1930,6 +1941,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) font.SetSize(ptsize); font.SetRotation(rotation); font.SetShear(shear); + font.SetFalseBoldWidth(falseBoldWidth); font.SetSpacing(spacing); font.SetFlags(flags); @@ -2456,11 +2468,11 @@ ServerApp::_CreateWindow(int32 code, BPrivate::LinkReceiver& link, ServerBitmap* bitmap = FindBitmap(bitmapToken); if (bitmap != NULL) { - window = new OffscreenServerWindow(title, this, clientReplyPort, + window = new (nothrow) OffscreenServerWindow(title, this, clientReplyPort, looperPort, token, bitmap); } } else { - window = new ServerWindow(title, this, clientReplyPort, looperPort, token); + window = new (nothrow) ServerWindow(title, this, clientReplyPort, looperPort, token); STRACE(("\nServerApp %s: New Window %s (%g:%g, %g:%g)\n", Signature(), title, frame.left, frame.top, frame.right, frame.bottom)); diff --git a/src/servers/app/ServerFont.cpp b/src/servers/app/ServerFont.cpp index 0bf910c832..6ae6413b85 100644 --- a/src/servers/app/ServerFont.cpp +++ b/src/servers/app/ServerFont.cpp @@ -113,12 +113,13 @@ is_white_space(uint32 charCode) \param spacing String spacing flag as defined in */ ServerFont::ServerFont(FontStyle& style, float size, - float rotation, float shear, + float rotation, float shear, float falseBoldWidth, uint16 flags, uint8 spacing) : fStyle(&style), fSize(size), fRotation(rotation), fShear(shear), + fFalseBoldWidth(falseBoldWidth), fBounds(0, 0, 0, 0), fFlags(flags), fSpacing(spacing), @@ -168,13 +169,14 @@ ServerFont& ServerFont::operator=(const ServerFont& font) { if (font.fStyle) { - fSize = font.fSize; - fRotation = font.fRotation; - fShear = font.fShear; - fFlags = font.fFlags; - fSpacing = font.fSpacing; - fEncoding = font.fEncoding; - fBounds = font.fBounds; + fSize = font.fSize; + fRotation = font.fRotation; + fShear = font.fShear; + fFalseBoldWidth = font.fFalseBoldWidth; + fFlags = font.fFlags; + fSpacing = font.fSpacing; + fEncoding = font.fEncoding; + fBounds = font.fBounds; SetStyle(font.fStyle); } diff --git a/src/servers/app/ServerFont.h b/src/servers/app/ServerFont.h index 55bf13bb01..f187778fdd 100644 --- a/src/servers/app/ServerFont.h +++ b/src/servers/app/ServerFont.h @@ -25,8 +25,9 @@ class ServerFont { ServerFont(); ServerFont(FontStyle& style, float size = 12.0, - float fRotation = 0.0, - float fShear = 90.0, + float rotation = 0.0, + float shear = 90.0, + float falseBoldWidth = 0.0, uint16 flags = 0, uint8 spacing = B_CHAR_SPACING); ServerFont(const ServerFont& font); @@ -48,6 +49,8 @@ class ServerFont { { return fShear; } float Rotation() const { return fRotation; } + float FalseBoldWidth() const + { return fFalseBoldWidth; } float Size() const { return fSize; } uint16 Face() const @@ -90,6 +93,8 @@ class ServerFont { { fSize = value; } void SetRotation(float value) { fRotation = value; } + void SetFalseBoldWidth(float value) + { fFalseBoldWidth = value; } void SetFace(uint32 face); bool IsFixedWidth() const @@ -162,6 +167,7 @@ protected: float fSize; float fRotation; float fShear; + float fFalseBoldWidth; BRect fBounds; uint32 fFlags; uint32 fSpacing; diff --git a/src/servers/app/drawing/Painter/font_support/AGGTextRenderer.cpp b/src/servers/app/drawing/Painter/font_support/AGGTextRenderer.cpp index 6cad2acb40..f4a33ff2d1 100644 --- a/src/servers/app/drawing/Painter/font_support/AGGTextRenderer.cpp +++ b/src/servers/app/drawing/Painter/font_support/AGGTextRenderer.cpp @@ -120,12 +120,15 @@ AGGTextRenderer::SetFont(const ServerFont &font) -font.Rotation() * PI / 180.0); agg::glyph_rendering glyphType = - fHinted && fEmbeddedTransformation.IsIdentity() ? + fHinted && fEmbeddedTransformation.IsIdentity() + && font.FalseBoldWidth() == 0.0 ? agg::glyph_ren_native_gray8 : agg::glyph_ren_outline; fFontEngine.load_font(font, glyphType, font.Size()); + fContour.width(font.FalseBoldWidth() * 2.0); + return true; } @@ -188,6 +191,11 @@ AGGTextRenderer::RenderString(const char* string, conv_font_trans_type; conv_font_trans_type transformedOutline(fCurves, transform); + typedef agg::conv_transform + conv_font_contour_trans_type; + conv_font_contour_trans_type transformedContourOutline(fContour, transform); + float falseBoldWidth = fContour.width(); + double x = 0.0; double y0 = 0.0; double y = y0; @@ -267,6 +275,8 @@ AGGTextRenderer::RenderString(const char* string, glyphBounds.OffsetBy(transformOffset); } else { fFontCache.init_embedded_adaptors(glyph, x, y); + if (falseBoldWidth != 0.0) + glyphBounds.InsetBy(-falseBoldWidth, -falseBoldWidth); glyphBounds = transform.TransformBounds(glyphBounds); } @@ -284,16 +294,13 @@ AGGTextRenderer::RenderString(const char* string, case agg::glyph_data_outline: { fRasterizer.reset(); - // NOTE: this function can be easily extended to handle - // conversion to contours, so that's why there is a lot of - // commented out code, I leave it here because I think it - // will be needed again. - - //if(fabs(0.0) <= 0.01) { - // For the sake of efficiency skip the - // contour converter if the weight is about zero. + if (fContour.width() == 0.0) { fRasterizer.add_path(transformedOutline); + } else { + fRasterizer.add_path(transformedContourOutline); + } + #if SHOW_GLYPH_BOUNDS agg::path_storage p; p.move_to(glyphBounds.left + 0.5, glyphBounds.top + 0.5); @@ -305,10 +312,6 @@ AGGTextRenderer::RenderString(const char* string, ps.width(1.0); fRasterizer.add_path(ps); #endif - /*} else { - //fRasterizer.add_path(fContour); - fRasterizer.add_path(transformedOutline); - }*/ agg::render_scanlines(fRasterizer, fScanline, *solidRenderer); break;