Rework the printer font stuff a little bit so that the Font API doesn't
authorhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Sep 2006 06:37:18 +0000 (06:37 +0000)
committerhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Sep 2006 06:37:18 +0000 (06:37 +0000)
        have to be changed.

        Reviewed by eseidel

        * WebCore.xcodeproj/project.pbxproj:
        * bridge/mac/WebCoreStringTruncator.mm:
        (truncateString):
        (+[WebCoreStringTruncator widthOfString:font:]):
        * platform/Font.cpp:
        (WebCore::Font::drawSimpleText):
        * platform/Font.h:
        * platform/TextStyle.h:
        (WebCore::TextStyle::TextStyle):
        (WebCore::TextStyle::attemptFontSubstitution):
        (WebCore::TextStyle::setRTL):
        * platform/mac/FontMac.mm:
        (WebCore::m_wordSpacing):
        (WebCore::Font::drawGlyphs):
        * platform/mac/ListBoxMac.mm:
        (itemTextRenderer):
        (groupLabelTextRenderer):
        (-[WebCoreTableView drawRow:clipRect:]):
        * platform/mac/PopUpButtonMac.mm:
        (PopUpButton::sizeHint):
        * platform/mac/TextFieldMac.mm:
        (-[NSSearchFieldCell _addStringToRecentSearches:]):
        * platform/mac/WebCoreTextRenderer.mm:
        (WebCoreDrawTextAtPoint):
        (WebCoreTextFloatWidth):
        * rendering/EllipsisBox.cpp:
        (WebCore::EllipsisBox::paint):
        * rendering/InlineTextBox.cpp:
        (WebCore::InlineTextBox::paint):
        * rendering/RenderImage.cpp:
        (WebCore::RenderImage::paint):
        * rendering/RenderListMarker.cpp:
        (WebCore::RenderListMarker::paint):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@16296 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
WebCore/ChangeLog
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/bridge/mac/WebCoreStringTruncator.mm
WebCore/platform/Font.cpp
WebCore/platform/Font.h
WebCore/platform/TextStyle.h
WebCore/platform/mac/FontMac.mm
WebCore/platform/mac/ListBoxMac.mm
WebCore/platform/mac/PopUpButtonMac.mm
WebCore/platform/mac/TextFieldMac.mm
WebCore/platform/mac/WebCoreTextRenderer.mm
WebCore/rendering/EllipsisBox.cpp
WebCore/rendering/InlineTextBox.cpp
WebCore/rendering/RenderImage.cpp
WebCore/rendering/RenderListMarker.cpp

index fc3a10da9a6733954c023ce48faf2355f274f7f3..ca5d1859f41e52636eac59336f3dfa117dc840cf 100644 (file)
@@ -1,3 +1,44 @@
+2006-09-10  David Hyatt  <hyatt@apple.com>
+
+        Rework the printer font stuff a little bit so that the Font API doesn't
+        have to be changed.
+
+        Reviewed by eseidel
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * bridge/mac/WebCoreStringTruncator.mm:
+        (truncateString):
+        (+[WebCoreStringTruncator widthOfString:font:]):
+        * platform/Font.cpp:
+        (WebCore::Font::drawSimpleText):
+        * platform/Font.h:
+        * platform/TextStyle.h:
+        (WebCore::TextStyle::TextStyle):
+        (WebCore::TextStyle::attemptFontSubstitution):
+        (WebCore::TextStyle::setRTL):
+        * platform/mac/FontMac.mm:
+        (WebCore::m_wordSpacing):
+        (WebCore::Font::drawGlyphs):
+        * platform/mac/ListBoxMac.mm:
+        (itemTextRenderer):
+        (groupLabelTextRenderer):
+        (-[WebCoreTableView drawRow:clipRect:]):
+        * platform/mac/PopUpButtonMac.mm:
+        (PopUpButton::sizeHint):
+        * platform/mac/TextFieldMac.mm:
+        (-[NSSearchFieldCell _addStringToRecentSearches:]):
+        * platform/mac/WebCoreTextRenderer.mm:
+        (WebCoreDrawTextAtPoint):
+        (WebCoreTextFloatWidth):
+        * rendering/EllipsisBox.cpp:
+        (WebCore::EllipsisBox::paint):
+        * rendering/InlineTextBox.cpp:
+        (WebCore::InlineTextBox::paint):
+        * rendering/RenderImage.cpp:
+        (WebCore::RenderImage::paint):
+        * rendering/RenderListMarker.cpp:
+        (WebCore::RenderListMarker::paint):
+
 2006-09-10  Brady Eidson  <beidson@apple.com>
 
         Reviewed by Maciej
index 218519fd7991b5af20830f90a9128fb4acb21eb4..8a685c02c4a4f74b65954c61c0f5dd4a390b750c 100644 (file)
                FAE04190097596C9000540BE /* SVGImageLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = FAE0418E097596C9000540BE /* SVGImageLoader.h */; };
 /* End PBXBuildFile section */
 
+/* Begin PBXBuildStyle section */
+               BC54D23C0AB521C200AA922E /* Development */ = {
+                       isa = PBXBuildStyle;
+                       buildSettings = {
+                               COPY_PHASE_STRIP = NO;
+                       };
+                       name = Development;
+               };
+               BC54D23D0AB521C200AA922E /* Deployment */ = {
+                       isa = PBXBuildStyle;
+                       buildSettings = {
+                               COPY_PHASE_STRIP = YES;
+                       };
+                       name = Deployment;
+               };
+/* End PBXBuildStyle section */
+
 /* Begin PBXContainerItemProxy section */
                DD041FF009D9E3250010AF2A /* PBXContainerItemProxy */ = {
                        isa = PBXContainerItemProxy;
                0867D690FE84028FC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        buildConfigurationList = 149C284308902B11008A9EFC /* Build configuration list for PBXProject "WebCore" */;
+                       buildSettings = {
+                       };
+                       buildStyles = (
+                               BC54D23C0AB521C200AA922E /* Development */,
+                               BC54D23D0AB521C200AA922E /* Deployment */,
+                       );
                        hasScannedForEncodings = 1;
                        knownRegions = (
                                English,
index 4d52191fbd2038406149bc7bb8829555f952de46..e0197c51e0a1d56fb75eacb49ecfd1ff9f3e1286 100644 (file)
@@ -112,7 +112,7 @@ static NSString *truncateString(NSString *string, float maxWidth, NSFont *font,
         currentFont = [font retain];
         FontPlatformData f(font);
         delete currentRenderer;
-        currentRenderer = new Font(f);
+        currentRenderer = new Font(f, ![[NSGraphicsContext currentContext] isDrawingToScreen]);
         ellipsis = ELLIPSIS_CHARACTER;
         currentEllipsisWidth = stringWidth(currentRenderer, &ellipsis, 1);
     }
@@ -219,7 +219,7 @@ static NSFont *defaultMenuFont(void)
     unichar *s = static_cast<unichar*>(malloc(sizeof(unichar) * length));
     [string getCharacters:s];
     FontPlatformData f(font);
-    Font fontRenderer(f);
+    Font fontRenderer(f, ![[NSGraphicsContext currentContext] isDrawingToScreen]);
     float width = stringWidth(&fontRenderer, s, length);
     free(s);
     return width;
index dc0a6d976f449658ed745d9525d91a45e019a55f..7d0f789777dd7cc637f4415dc7bb0874062b15a7 100644 (file)
@@ -501,7 +501,7 @@ void Font::drawSimpleText(GraphicsContext* context, const TextRun& run, const Te
     while (nextGlyph < glyphBuffer.size()) {
         const FontData* nextFontData = glyphBuffer.fontDataAt(nextGlyph);
         if (nextFontData != fontData) {
-            drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint, style.usePrinterFonts());
+            drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
             lastFrom = nextGlyph;
             fontData = nextFontData;
             startPoint.setX(nextX);
@@ -509,7 +509,7 @@ void Font::drawSimpleText(GraphicsContext* context, const TextRun& run, const Te
         nextX += glyphBuffer.advanceAt(nextGlyph);
         nextGlyph++;
     }
-    drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint, style.usePrinterFonts());
+    drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
 }
 
 void Font::drawText(GraphicsContext* context, const TextRun& run, const TextStyle& style, const FloatPoint& point) const
index f3520654dd22dcfc92a9f1b9763d1dfbeeb64e61..693c64087ed29650e630048d9f40bb319dc4af37 100644 (file)
@@ -82,7 +82,7 @@ public:
     Font();
     Font(const FontDescription&, short letterSpacing, short wordSpacing);
 #if PLATFORM(MAC)
-    Font(const FontPlatformData&); // This constructor is only used by Mac-specific code that already has a native font.
+    Font(const FontPlatformData&, bool isPrinting); // This constructor is only used by Mac-specific code that already has a native font.
 #endif
     ~Font();
     
@@ -154,7 +154,7 @@ private:
     // FIXME: This will eventually be cross-platform, but we want to keep Windows compiling for now.
     bool canUseGlyphCache(const TextRun&) const;
     void drawSimpleText(GraphicsContext*, const TextRun&, const TextStyle&, const FloatPoint&) const;
-    void drawGlyphs(GraphicsContext*, const FontData*, const GlyphBuffer&, int from, int to, const FloatPoint&, bool usePrinterFont) const;
+    void drawGlyphs(GraphicsContext*, const FontData*, const GlyphBuffer&, int from, int to, const FloatPoint&) const;
     void drawComplexText(GraphicsContext*, const TextRun&, const TextStyle&, const FloatPoint&) const;
     float floatWidthForSimpleText(const TextRun&, const TextStyle&, const FontData* substituteFontData,
                                   float* startX, GlyphBuffer*) const;
index 481158c052d9e7d2f7e329a8980050385222014a..1dfff92d10d923ae5b04799f6a06a2205943dcbc 100644 (file)
@@ -26,7 +26,7 @@ namespace WebCore {
 class TextStyle {
 public:
     TextStyle(int tabWidth = 0, int xpos = 0, int padding = 0, bool rtl = false, bool directionalOverride = false,
-              bool applyRunRounding = true, bool applyWordRounding = true, bool attemptFontSubstitution = true, bool usePrinterFonts = false)
+              bool applyRunRounding = true, bool applyWordRounding = true, bool attemptFontSubstitution = true)
         : m_tabWidth(tabWidth)
         , m_xpos(xpos)
         , m_padding(padding)
@@ -35,7 +35,6 @@ public:
         , m_applyRunRounding(applyRunRounding)
         , m_applyWordRounding(applyWordRounding)
         , m_attemptFontSubstitution(attemptFontSubstitution)
-        , m_usePrinterFonts(usePrinterFonts)
     {
     }
 
@@ -48,11 +47,9 @@ public:
     bool applyRunRounding() const { return m_applyRunRounding; }
     bool applyWordRounding() const { return m_applyWordRounding; }
     bool attemptFontSubstitution() const { return m_attemptFontSubstitution; }
-    bool usePrinterFonts() const { return m_usePrinterFonts; }
 
     void disableRoundingHacks() { m_applyRunRounding = m_applyWordRounding = false; }
     void setRTL(bool b) { m_rtl = b; }
-    void setUsePrinterFonts(bool b) { m_usePrinterFonts = b; }
     
 private:
     int m_tabWidth;
@@ -63,7 +60,6 @@ private:
     bool m_applyRunRounding;
     bool m_applyWordRounding;
     bool m_attemptFontSubstitution;
-    bool m_usePrinterFonts;
 };
 
 }
index 42879f3489349d4badc0d3c130c903dfcb044b70..6c1d6b9b6236555b216255f2a67572cbb0fa05d2 100644 (file)
@@ -424,9 +424,10 @@ static void disposeATSULayoutParameters(ATSULayoutParameters *params)
     delete []params->m_fonts;
 }
 
-Font::Font(const FontPlatformData& fontData)
+Font::Font(const FontPlatformData& fontData, bool isPrinterFont)
 :m_letterSpacing(0), m_wordSpacing(0)
 {
+    m_fontDescription.setUsePrinterFont(isPrinterFont);
     m_fontList = new FontFallbackList();
     m_fontList->setPlatformFont(fontData);
 }
@@ -555,7 +556,7 @@ int Font::offsetForPositionForComplexText(const TextRun& run, const TextStyle& s
     return offset - adjustedRun.from();
 }
 
-void Font::drawGlyphs(GraphicsContext* context, const FontData* font, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point, bool usePrinterFont) const
+void Font::drawGlyphs(GraphicsContext* context, const FontData* font, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point) const
 {
     CGContextRef cgContext = context->platformContext();
 
@@ -564,7 +565,7 @@ void Font::drawGlyphs(GraphicsContext* context, const FontData* font, const Glyp
     
     const FontPlatformData& platformData = font->platformData();
     NSFont* drawFont;
-    if (!usePrinterFont) {
+    if (!isPrinterFont()) {
         drawFont = [platformData.font screenFont];
         if (drawFont != platformData.font)
             // We are getting this in too many places (3406411); use ERROR so it only prints on debug versions for now. (We should debug this also, eventually).
index f2f9569196d7ace96094ab3147b163078a4b2846..59dd9184c9c353c28beeca9023bb889bf7e5a5b4 100644 (file)
@@ -84,13 +84,13 @@ static Font* itemTextRenderer(bool isPrinting)
     if (!isPrinting) {
         if (itemScreenRenderer == nil) {
             FontPlatformData font(itemFont());
-            itemScreenRenderer = new Font(font);
+            itemScreenRenderer = new Font(font, isPrinting);
         }
         return itemScreenRenderer;
     } else {
         if (itemPrinterRenderer == nil) {
             FontPlatformData font(itemFont(), true);
-            itemPrinterRenderer = new Font(font);
+            itemPrinterRenderer = new Font(font, isPrinting);
         }
         return itemPrinterRenderer;
     }
@@ -101,13 +101,13 @@ static Font* groupLabelTextRenderer(bool isPrinting)
     if (!isPrinting) {
         if (groupLabelScreenRenderer == nil) {
             FontPlatformData font([NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]]);
-            groupLabelScreenRenderer = new Font(font);
+            groupLabelScreenRenderer = new Font(font, isPrinting);
         }
         return groupLabelScreenRenderer;
     } else {
         if (groupLabelPrinterRenderer == nil) {
             FontPlatformData font([NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]], true);
-            groupLabelPrinterRenderer = new Font(font);
+            groupLabelPrinterRenderer = new Font(font, isPrinting);
         }
         return groupLabelPrinterRenderer;
     }
@@ -702,7 +702,6 @@ static Boolean ListBoxTypeSelectCallback(UInt32 index, void *listDataPtr, void *
     WebCore::TextStyle style;
     style.setRTL(rtl);
     style.disableRoundingHacks();
-    style.setUsePrinterFonts(isPrinting);
 
     TextRun run(reinterpret_cast<const UniChar *>(item.string.unicode()), item.string.length());
     
index 0df9556f7c7768e6c929d9322c70cfe0727f34d0..fe6e7b125e9159441904219615905908b4207d51 100644 (file)
@@ -170,10 +170,10 @@ IntSize PopUpButton::sizeHint() const
         if (i != e) {
             RenderWidget *client = static_cast<RenderWidget *>(Widget::client());
             bool isPrinting = client->view()->printingMode();
-            FontPlatformData itemFont([button font], isPrinting);
-            FontPlatformData labelFont(this->labelFont(), isPrinting);
-            Font itemRenderer(itemFont);
-            Font labelRenderer(labelFont);
+            FontPlatformData itemFont([button font]);
+            FontPlatformData labelFont(this->labelFont());
+            Font itemRenderer(itemFont, isPrinting);
+            Font labelRenderer(labelFont, isPrinting);
             do {
                 const DeprecatedString &s = (*i).string;
                 bool isGroupLabel = ((*i).type == ListBoxGroupLabel);
index 3d96208adf4099c76baa5d7b4bce411de54b7ddc..75d2ee5546895c8fe47026c95abe0939b149f935 100644 (file)
@@ -253,8 +253,8 @@ IntSize TextField::sizeForCharacterWidth(int numCharacters) const
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
     RenderWidget *client = static_cast<RenderWidget *>(Widget::client());
-    FontPlatformData font([textField font], client->view()->printingMode());
-    Font renderer(font);
+    FontPlatformData font([textField font]);
+    Font renderer(font, client->view()->printingMode());
 
     NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
     size.height += [layoutManager defaultLineHeightForFont:font.font];
index 2b407e2ee8c542b9a06a0b00b2a1acbe7cc0106e..e7ed07e6840b549f0ce9d474fa88b070073fa930 100644 (file)
@@ -46,11 +46,10 @@ void WebCoreDrawTextAtPoint(const UniChar* buffer, unsigned length, NSPoint poin
         CGContextScaleCTM(cgContext, 1.0, -1.0);
     
     FontPlatformData f(font);
-    Font renderer(f);
+    Font renderer(f, ![[NSGraphicsContext currentContext] isDrawingToScreen]);
     TextRun run(buffer, length);
     TextStyle style;
     style.disableRoundingHacks();
-    style.setUsePrinterFonts(![[NSGraphicsContext currentContext] isDrawingToScreen]);
     CGFloat red, green, blue, alpha;
     [[textColor colorUsingColorSpaceName:NSDeviceRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
     graphicsContext.setPen(makeRGBA((int)(red * 255), (int)(green * 255), (int)(blue * 255), (int)(alpha * 255)));
@@ -62,7 +61,7 @@ void WebCoreDrawTextAtPoint(const UniChar* buffer, unsigned length, NSPoint poin
 float WebCoreTextFloatWidth(const UniChar* buffer, unsigned length , NSFont* font)
 {
     FontPlatformData f(font);
-    Font renderer(f);
+    Font renderer(f, ![[NSGraphicsContext currentContext] isDrawingToScreen]);
     TextRun run(buffer, length);
     TextStyle style;
     style.disableRoundingHacks();
index 10c0cee2fcd54bfed2f4e2625e6bbaee8663e2b8..932696ad4b679d553ec9987114e58061bdc01c6a 100644 (file)
@@ -48,7 +48,6 @@ void EllipsisBox::paint(RenderObject::PaintInfo& i, int _tx, int _ty)
 
     const String& str = m_str;
     TextStyle textStyle(0, 0, 0, false, _style->visuallyOrdered());
-    textStyle.setUsePrinterFonts(object()->document()->printing());
     p->drawText(TextRun(str.impl()), IntPoint(m_x + _tx, m_y + _ty + m_baseline), textStyle);
 
     if (setShadow)
index e13d1f90af8fb9e02fcb06646c2385a941c6de01..9d6bc44d335e4d9cdd834f8b0d6ec0ce2e033ea9 100644 (file)
@@ -344,7 +344,6 @@ void InlineTextBox::paint(RenderObject::PaintInfo& i, int tx, int ty)
     StringImpl* textStr = textObject()->string();
 
     TextStyle textStyle(textObject()->tabWidth(), textPos(), m_toAdd, m_reversed, m_dirOverride || styleToUse->visuallyOrdered());
-    textStyle.setUsePrinterFonts(isPrinting);
 
     if (!paintSelectedTextOnly && !paintSelectedTextSeparately) {
         // paint all the text
index a300e3f9dcda9ea7caf67512d57b6bfb1ea94afa..4a77450613e359177f95b22a6c20a62fc1579255 100644 (file)
@@ -254,14 +254,12 @@ void RenderImage::paint(PaintInfo& i, int _tx, int _ty)
                 // Only draw the alt text if it'll fit within the content box,
                 // and only if it fits above the error image.
                 TextRun textRun(reinterpret_cast<const UChar*>(text.unicode()), text.length());
-                TextStyle textStyle;
-                textStyle.setUsePrinterFonts(view()->printingMode());
                 int textWidth = font.width(textRun);
                 if (errorPictureDrawn) {
                     if (usableWidth >= textWidth && font.height() <= imageY)
-                        p->drawText(textRun, IntPoint(ax, ay + ascent), textStyle);
+                        p->drawText(textRun, IntPoint(ax, ay + ascent));
                 } else if (usableWidth >= textWidth && cHeight >= font.height())
-                    p->drawText(textRun, IntPoint(ax, ay + ascent), textStyle);
+                    p->drawText(textRun, IntPoint(ax, ay + ascent));
             }
         }
     } else if (m_cachedImage) {
index aaa89172781fc722936ec823bd1c33579adf720e..c40326d3bfa78c4df6aa0009a6884474859445e3 100644 (file)
@@ -232,19 +232,17 @@ void RenderListMarker::paint(PaintInfo& i, int _tx, int _ty)
         if (!m_item.isEmpty()) {
             const Font& font = style()->font();
             TextRun textRun(reinterpret_cast<const UChar*>(m_item.unicode()), m_item.length());
-            TextStyle textStyle;
-            textStyle.setUsePrinterFonts(view()->printingMode());
             if (style()->direction() == LTR) {
                 int width = font.width(textRun);
-                p->drawText(textRun, marker.location(), textStyle);
+                p->drawText(textRun, marker.location());
                 UChar periodSpace[2] = { '.', ' ' };
-                p->drawText(TextRun(periodSpace, 2), marker.location() + IntSize(width, 0), textStyle);
+                p->drawText(TextRun(periodSpace, 2), marker.location() + IntSize(width, 0));
             } else {
                 UChar spacePeriod[2] = { ' ', '.' };
                 TextRun spacePeriodRun(spacePeriod, 2);
                 int width = font.width(spacePeriodRun);
-                p->drawText(spacePeriodRun, marker.location(), textStyle);
-                p->drawText(textRun, marker.location() + IntSize(width, 0), textStyle);
+                p->drawText(spacePeriodRun, marker.location());
+                p->drawText(textRun, marker.location() + IntSize(width, 0));
             }
         }
     }