Diff
Modified: trunk/Source/WebCore/ChangeLog (165685 => 165686)
--- trunk/Source/WebCore/ChangeLog 2014-03-15 23:17:05 UTC (rev 165685)
+++ trunk/Source/WebCore/ChangeLog 2014-03-16 00:17:56 UTC (rev 165686)
@@ -1,3 +1,28 @@
+2014-03-14 Myles C. Maxfield <mmaxfi...@apple.com>
+
+ RenderTextControl::hasValidAvgCharWidth doesn't detect System Font
+ https://bugs.webkit.org/show_bug.cgi?id=130168
+
+ Reviewed by Dean Jackson.
+
+ No new tests.
+
+ * platform/graphics/Font.cpp: Moved functions from RenderTextControl
+ (WebCore::Font::hasValidAverageCharWidth):
+ (WebCore::Font::fastAverageCharWidthIfAvailable):
+ * platform/graphics/Font.h:
+ * rendering/RenderTextControl.cpp: Moved functions to Font.cpp
+ (WebCore::RenderTextControl::getAverageCharWidth): Removed redundant function argument
+ (WebCore::RenderTextControl::computeIntrinsicLogicalWidths):
+ * rendering/RenderTextControl.h:
+ * rendering/RenderTextControlMultiLine.cpp:
+ (WebCore::RenderTextControlMultiLine::getAverageCharWidth): Removed redundant function argument
+ * rendering/RenderTextControlMultiLine.h:
+ * rendering/RenderTextControlSingleLine.cpp:
+ (WebCore::RenderTextControlSingleLine::getAverageCharWidth): Removed redundant function argument
+ (WebCore::RenderTextControlSingleLine::preferredContentLogicalWidth):
+ * rendering/RenderTextControlSingleLine.h:
+
2014-03-15 David Kilzer <ddkil...@apple.com>
[iOS] Define SYSTEM_VERSION_PREFIX consistently
Modified: trunk/Source/WebCore/platform/graphics/Font.cpp (165685 => 165686)
--- trunk/Source/WebCore/platform/graphics/Font.cpp 2014-03-15 23:17:05 UTC (rev 165685)
+++ trunk/Source/WebCore/platform/graphics/Font.cpp 2014-03-16 00:17:56 UTC (rev 165686)
@@ -426,6 +426,82 @@
}
#endif
+
+
+static const char* fontFamiliesWithInvalidCharWidth[] = {
+ "American Typewriter",
+ "Arial Hebrew",
+ "Chalkboard",
+ "Cochin",
+ "Corsiva Hebrew",
+ "Courier",
+ "Euphemia UCAS",
+ "Geneva",
+ "Gill Sans",
+ "Hei",
+ "Helvetica",
+ "Hoefler Text",
+ "InaiMathi",
+ "Kai",
+ "Lucida Grande",
+ "Marker Felt",
+ "Monaco",
+ "Mshtakan",
+ "New Peninim MT",
+ "Osaka",
+ "Raanana",
+ "STHeiti",
+ "Symbol",
+ "Times",
+ "Apple Braille",
+ "Apple LiGothic",
+ "Apple LiSung",
+ "Apple Symbols",
+ "AppleGothic",
+ "AppleMyungjo",
+ "#GungSeo",
+ "#HeadLineA",
+ "#PCMyungjo",
+ "#PilGi",
+};
+
+// For font families where any of the fonts don't have a valid entry in the OS/2 table
+// for avgCharWidth, fallback to the legacy webkit behavior of getting the avgCharWidth
+// from the width of a '0'. This only seems to apply to a fixed number of Mac fonts,
+// but, in order to get similar rendering across platforms, we do this check for
+// all platforms.
+bool Font::hasValidAverageCharWidth() const
+{
+ AtomicString family = firstFamily();
+ if (family.isEmpty())
+ return false;
+
+ // Internal fonts on OS X also have an invalid entry in the table for avgCharWidth.
+ // They are hidden by having a name that begins with a period, so simply search
+ // for that here rather than try to keep the list up to date.
+ if (family.startsWith('.') || family == "System Font")
+ return false;
+
+ static HashSet<AtomicString>* fontFamiliesWithInvalidCharWidthMap = 0;
+
+ if (!fontFamiliesWithInvalidCharWidthMap) {
+ fontFamiliesWithInvalidCharWidthMap = new HashSet<AtomicString>;
+
+ for (size_t i = 0; i < WTF_ARRAY_LENGTH(fontFamiliesWithInvalidCharWidth); ++i)
+ fontFamiliesWithInvalidCharWidthMap->add(AtomicString(fontFamiliesWithInvalidCharWidth[i]));
+ }
+
+ return !fontFamiliesWithInvalidCharWidthMap->contains(family);
+}
+
+bool Font::fastAverageCharWidthIfAvailable(float& width) const
+{
+ bool success = hasValidAverageCharWidth();
+ if (success)
+ width = roundf(primaryFont()->avgCharWidth()); // FIXME: primaryFont() might not correspond to firstFamily().
+ return success;
+}
+
FloatRect Font::selectionRectForText(const TextRun& run, const FloatPoint& point, int h, int from, int to) const
{
to = (to == -1 ? run.length() : to);
Modified: trunk/Source/WebCore/platform/graphics/Font.h (165685 => 165686)
--- trunk/Source/WebCore/platform/graphics/Font.h 2014-03-15 23:17:05 UTC (rev 165685)
+++ trunk/Source/WebCore/platform/graphics/Font.h 2014-03-16 00:17:56 UTC (rev 165686)
@@ -154,6 +154,8 @@
float spaceWidth() const { return primaryFont()->spaceWidth() + m_letterSpacing; }
float tabWidth(const SimpleFontData&, unsigned tabSize, float position) const;
float tabWidth(unsigned tabSize, float position) const { return tabWidth(*primaryFont(), tabSize, position); }
+ bool hasValidAverageCharWidth() const;
+ bool fastAverageCharWidthIfAvailable(float &width) const; // returns true on success
int emphasisMarkAscent(const AtomicString&) const;
int emphasisMarkDescent(const AtomicString&) const;
Modified: trunk/Source/WebCore/rendering/RenderTextControl.cpp (165685 => 165686)
--- trunk/Source/WebCore/rendering/RenderTextControl.cpp 2014-03-15 23:17:05 UTC (rev 165685)
+++ trunk/Source/WebCore/rendering/RenderTextControl.cpp 2014-03-16 00:17:56 UTC (rev 165686)
@@ -172,76 +172,12 @@
result.setLocalPoint(localPoint);
}
-static const char* fontFamiliesWithInvalidCharWidth[] = {
- "American Typewriter",
- "Arial Hebrew",
- "Chalkboard",
- "Cochin",
- "Corsiva Hebrew",
- "Courier",
- "Euphemia UCAS",
- "Geneva",
- "Gill Sans",
- "Hei",
- "Helvetica",
- "Hoefler Text",
- "InaiMathi",
- "Kai",
- "Lucida Grande",
- "Marker Felt",
- "Monaco",
- "Mshtakan",
- "New Peninim MT",
- "Osaka",
- "Raanana",
- "STHeiti",
- "Symbol",
- "Times",
- "Apple Braille",
- "Apple LiGothic",
- "Apple LiSung",
- "Apple Symbols",
- "AppleGothic",
- "AppleMyungjo",
- "#GungSeo",
- "#HeadLineA",
- "#PCMyungjo",
- "#PilGi",
-};
-
-// For font families where any of the fonts don't have a valid entry in the OS/2 table
-// for avgCharWidth, fallback to the legacy webkit behavior of getting the avgCharWidth
-// from the width of a '0'. This only seems to apply to a fixed number of Mac fonts,
-// but, in order to get similar rendering across platforms, we do this check for
-// all platforms.
-bool RenderTextControl::hasValidAvgCharWidth(AtomicString family)
+float RenderTextControl::getAverageCharWidth()
{
- if (family.isEmpty())
- return false;
+ float width;
+ if (style().font().fastAverageCharWidthIfAvailable(width))
+ return width;
- // Internal fonts on OS X also have an invalid entry in the table for avgCharWidth.
- // They are hidden by having a name that begins with a period, so simply search
- // for that here rather than try to keep the list up to date.
- if (family.startsWith('.'))
- return false;
-
- static HashSet<AtomicString>* fontFamiliesWithInvalidCharWidthMap = 0;
-
- if (!fontFamiliesWithInvalidCharWidthMap) {
- fontFamiliesWithInvalidCharWidthMap = new HashSet<AtomicString>;
-
- for (size_t i = 0; i < WTF_ARRAY_LENGTH(fontFamiliesWithInvalidCharWidth); ++i)
- fontFamiliesWithInvalidCharWidthMap->add(AtomicString(fontFamiliesWithInvalidCharWidth[i]));
- }
-
- return !fontFamiliesWithInvalidCharWidthMap->contains(family);
-}
-
-float RenderTextControl::getAvgCharWidth(AtomicString family)
-{
- if (hasValidAvgCharWidth(family))
- return roundf(style().font().primaryFont()->avgCharWidth());
-
const UChar ch = '0';
const String str = String(&ch, 1);
const Font& font = style().font();
@@ -260,8 +196,7 @@
void RenderTextControl::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const
{
// Use average character width. Matches IE.
- const AtomicString& family = style().font().firstFamily();
- maxLogicalWidth = preferredContentLogicalWidth(const_cast<RenderTextControl*>(this)->getAvgCharWidth(family));
+ maxLogicalWidth = preferredContentLogicalWidth(const_cast<RenderTextControl*>(this)->getAverageCharWidth());
if (RenderBox* innerTextRenderBox = innerTextElement()->renderBox())
maxLogicalWidth += innerTextRenderBox->paddingStart() + innerTextRenderBox->paddingEnd();
if (!style().logicalWidth().isPercent())
Modified: trunk/Source/WebCore/rendering/RenderTextControl.h (165685 => 165686)
--- trunk/Source/WebCore/rendering/RenderTextControl.h 2014-03-15 23:17:05 UTC (rev 165685)
+++ trunk/Source/WebCore/rendering/RenderTextControl.h 2014-03-16 00:17:56 UTC (rev 165686)
@@ -62,8 +62,7 @@
float scaleEmToUnits(int x) const;
- static bool hasValidAvgCharWidth(AtomicString family);
- virtual float getAvgCharWidth(AtomicString family);
+ virtual float getAverageCharWidth();
virtual LayoutUnit preferredContentLogicalWidth(float charWidth) const = 0;
virtual LayoutUnit computeControlLogicalHeight(LayoutUnit lineHeight, LayoutUnit nonContentHeight) const = 0;
Modified: trunk/Source/WebCore/rendering/RenderTextControlMultiLine.cpp (165685 => 165686)
--- trunk/Source/WebCore/rendering/RenderTextControlMultiLine.cpp 2014-03-15 23:17:05 UTC (rev 165685)
+++ trunk/Source/WebCore/rendering/RenderTextControlMultiLine.cpp 2014-03-16 00:17:56 UTC (rev 165686)
@@ -59,17 +59,17 @@
return true;
}
-float RenderTextControlMultiLine::getAvgCharWidth(AtomicString family)
+float RenderTextControlMultiLine::getAverageCharWidth()
{
#if !PLATFORM(IOS)
// Since Lucida Grande is the default font, we want this to match the width
// of Courier New, the default font for textareas in IE, Firefox and Safari Win.
// 1229 is the avgCharWidth value in the OS/2 table for Courier New.
- if (family == "Lucida Grande")
+ if (style().font().firstFamily() == "Lucida Grande")
return scaleEmToUnits(1229);
#endif
- return RenderTextControl::getAvgCharWidth(family);
+ return RenderTextControl::getAverageCharWidth();
}
LayoutUnit RenderTextControlMultiLine::preferredContentLogicalWidth(float charWidth) const
Modified: trunk/Source/WebCore/rendering/RenderTextControlMultiLine.h (165685 => 165686)
--- trunk/Source/WebCore/rendering/RenderTextControlMultiLine.h 2014-03-15 23:17:05 UTC (rev 165685)
+++ trunk/Source/WebCore/rendering/RenderTextControlMultiLine.h 2014-03-16 00:17:56 UTC (rev 165686)
@@ -42,7 +42,7 @@
virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) override;
- virtual float getAvgCharWidth(AtomicString family);
+ virtual float getAverageCharWidth();
virtual LayoutUnit preferredContentLogicalWidth(float charWidth) const;
virtual LayoutUnit computeControlLogicalHeight(LayoutUnit lineHeight, LayoutUnit nonContentHeight) const override;
virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const;
Modified: trunk/Source/WebCore/rendering/RenderTextControlSingleLine.cpp (165685 => 165686)
--- trunk/Source/WebCore/rendering/RenderTextControlSingleLine.cpp 2014-03-15 23:17:05 UTC (rev 165685)
+++ trunk/Source/WebCore/rendering/RenderTextControlSingleLine.cpp 2014-03-16 00:17:56 UTC (rev 165686)
@@ -312,18 +312,18 @@
return clipRect;
}
-float RenderTextControlSingleLine::getAvgCharWidth(AtomicString family)
+float RenderTextControlSingleLine::getAverageCharWidth()
{
#if !PLATFORM(IOS)
// Since Lucida Grande is the default font, we want this to match the width
// of MS Shell Dlg, the default font for textareas in Firefox, Safari Win and
// IE for some encodings (in IE, the default font is encoding specific).
// 901 is the avgCharWidth value in the OS/2 table for MS Shell Dlg.
- if (family == "Lucida Grande")
+ if (style().font().firstFamily() == "Lucida Grande")
return scaleEmToUnits(901);
#endif
- return RenderTextControl::getAvgCharWidth(family);
+ return RenderTextControl::getAverageCharWidth();
}
LayoutUnit RenderTextControlSingleLine::preferredContentLogicalWidth(float charWidth) const
@@ -345,7 +345,7 @@
// 4027 is the (xMax - xMin) value in the "head" font table for MS Shell Dlg.
if (family == "Lucida Grande")
maxCharWidth = scaleEmToUnits(4027);
- else if (hasValidAvgCharWidth(family))
+ else if (style().font().hasValidAverageCharWidth())
maxCharWidth = roundf(style().font().primaryFont()->maxCharWidth());
#endif
Modified: trunk/Source/WebCore/rendering/RenderTextControlSingleLine.h (165685 => 165686)
--- trunk/Source/WebCore/rendering/RenderTextControlSingleLine.h 2014-03-15 23:17:05 UTC (rev 165685)
+++ trunk/Source/WebCore/rendering/RenderTextControlSingleLine.h 2014-03-16 00:17:56 UTC (rev 165686)
@@ -73,7 +73,7 @@
virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = 0) override final;
int textBlockWidth() const;
- virtual float getAvgCharWidth(AtomicString family) override;
+ virtual float getAverageCharWidth() override;
virtual LayoutUnit preferredContentLogicalWidth(float charWidth) const override;
virtual LayoutUnit computeControlLogicalHeight(LayoutUnit lineHeight, LayoutUnit nonContentHeight) const override;