diff options
author | pamg@google.com <pamg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-08 15:06:18 +0000 |
---|---|---|
committer | pamg@google.com <pamg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-08 15:06:18 +0000 |
commit | 83167bcb0764074bfaaa1b717da646eaefcbca29 (patch) | |
tree | 460395a1625eee0ac7da55ec6edc16a355560ef6 /webkit | |
parent | 8389983143f7befa6f5231a2d7a4cf37965e4558 (diff) | |
download | chromium_src-83167bcb0764074bfaaa1b717da646eaefcbca29.zip chromium_src-83167bcb0764074bfaaa1b717da646eaefcbca29.tar.gz chromium_src-83167bcb0764074bfaaa1b717da646eaefcbca29.tar.bz2 |
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@565 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/build/port/port.vcproj | 8 | ||||
-rw-r--r-- | webkit/pending/SimpleFontData.cpp | 1 | ||||
-rw-r--r-- | webkit/port/platform/FontMetrics.cpp | 331 | ||||
-rw-r--r-- | webkit/port/platform/FontMetrics.h | 132 | ||||
-rw-r--r-- | webkit/port/platform/graphics/FontCacheWin.cpp | 42 | ||||
-rw-r--r-- | webkit/port/platform/graphics/FontCustomPlatformData.cpp | 2 | ||||
-rw-r--r-- | webkit/port/platform/graphics/FontPlatformData.h | 12 | ||||
-rw-r--r-- | webkit/port/platform/graphics/FontPlatformDataWin.cpp | 3 | ||||
-rw-r--r-- | webkit/port/platform/graphics/GlyphPageTreeNodeWin.cpp | 20 | ||||
-rw-r--r-- | webkit/port/platform/graphics/SimpleFontDataWin.cpp | 88 |
10 files changed, 18 insertions, 621 deletions
diff --git a/webkit/build/port/port.vcproj b/webkit/build/port/port.vcproj index 1da2bb1..7c08873 100644 --- a/webkit/build/port/port.vcproj +++ b/webkit/build/port/port.vcproj @@ -720,14 +720,6 @@ > </File> <File - RelativePath="..\..\port\platform\FontMetrics.cpp" - > - </File> - <File - RelativePath="..\..\port\platform\FontMetrics.h" - > - </File> - <File RelativePath="..\..\port\platform\FramelessScrollView.cpp" > </File> diff --git a/webkit/pending/SimpleFontData.cpp b/webkit/pending/SimpleFontData.cpp index 7cf3a4d..fa0e2b1 100644 --- a/webkit/pending/SimpleFontData.cpp +++ b/webkit/pending/SimpleFontData.cpp @@ -31,7 +31,6 @@ #include "SimpleFontData.h" #include "Font.h" -#include "FontMetrics.h" #if ENABLE(SVG_FONTS) #include "SVGFontData.h" diff --git a/webkit/port/platform/FontMetrics.cpp b/webkit/port/platform/FontMetrics.cpp deleted file mode 100644 index 147010a..0000000 --- a/webkit/port/platform/FontMetrics.cpp +++ /dev/null @@ -1,331 +0,0 @@ -// Copyright (c) 2008, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#include "config.h" -#include "FontMetrics.h" - -#include <map> -#include <string> - -#include "base/file_util.h" -#include "base/string_util.h" -#include "webkit/glue/glue_util.h" -#include "webkit/glue/webkit_glue.h" - -// Notes about the .afm file format: -// - Very unforgiving. -// - Metrics given on the right are scaled by the 'unitsPerEm' value: if -// unitsPerEm = 2048, then a width of 1024 corresponds to .5. This is -// then multiplied by the point size to find the final metric. -// - The glyph width section must be sorted by starting glyph. -// - The glyph width section must cover the full range of glyphs from [1,65535]. - -namespace WebCore { - -// static -bool FontMetrics::parseFontMetricsFile(FILE* fp, FontMetrics* info) -{ - if (fscanf_s(fp, "unitsPerEm = %d\n", &info->unitsPerEm) != 1) - return false; - if (fscanf_s(fp, "ascent = %d\n", &info->ascent) != 1) - return false; - if (fscanf_s(fp, "descent = %d\n", &info->descent) != 1) - return false; - if (fscanf_s(fp, "lineGap = %d\n", &info->lineGap) != 1) - return false; - if (fscanf_s(fp, "xHeight = %d\n", &info->xHeight) != 1) - return false; - - int numGlyphs; - if (fscanf_s(fp, "numGlyphs = %d\n", &numGlyphs) != 1) - return false; - - for (int i = 0; i < numGlyphs; ++i) { - FontMetrics::GlyphRange range; - if (fscanf_s(fp, "[%d,%d] = %d\n", - &range.start, &range.end, &range.value) != 3) { - return false; - } - info->glyphWidths.append(range); - } - - int numChars; - if (fscanf_s(fp, "numChars = %d\n", &numChars) != 1) - return false; - - for (int i = 0; i < numChars; ++i) { - int ch, glyph; - if (fscanf_s(fp, "%d = %d\n", &ch, &glyph) != 2) - return false; - info->charToGlyphMap.set(ch, glyph); - } - - return true; -} - -// static -const FontMetrics* FontMetrics::lookup(const String& family, - bool bold, - bool italic) -{ - // FontMetrics exist only during layout tests. - if (!webkit_glue::IsLayoutTestMode()) - return NULL; - - typedef std::map<std::wstring, FontMetrics*> FontMetricsMap; - static FontMetricsMap fontMetricsCache; - - // Generate the filename: "<family>[b][i].afm" - String lower_family = family.lower(); - std::wstring filename = webkit_glue::StringToStdWString(lower_family); - std::replace(filename.begin(), filename.end(), L' ', L'_'); - if (bold) - filename += 'b'; - if (italic) - filename += 'i'; - filename += L".afm"; - - if (fontMetricsCache.find(filename) != fontMetricsCache.end()) - return fontMetricsCache[filename]; - - std::wstring path; - webkit_glue::GetApplicationDirectory(&path); - file_util::AppendToPath(&path, L"fonts"); - file_util::AppendToPath(&path, filename); - - FILE* fp; - fopen_s(&fp, WideToUTF8(path).c_str(), "r"); - if (!fp) { - // Try to fall back on a font without bold/italic. - // Note: the order of these fallback cases is important. A bold+italic - // font should fall back to bold (with synthetic italics, which doesn't - // appear to influence layout) if it doesn't exist. This seems to match - // what Apple does on Windows. - if (italic) - return lookup(family, bold, false); - if (bold) { - // If we want bold but don't have it, do as Apple would do and use a - // synethetic offset. - const FontMetrics* info = lookup(family, false, italic); - if (info) { - FontMetrics* bold_info = new FontMetrics(*info); - bold_info->syntheticBoldOffset = 1.0f; - fontMetricsCache[filename] = bold_info; - return bold_info; - } - return NULL; - } - return NULL; - } - - // Read in the data. - FontMetrics* info = new FontMetrics; - info->family = lower_family; - info->syntheticBoldOffset = 0.0f; - info->isSystemFont = (lower_family == "lucida grande"); - - if (!parseFontMetricsFile(fp, info)) { - LOG_ERROR("FontMetrics::lookup: bad file format for file '%S'", - path.c_str()); - ASSERT_NOT_REACHED(); - - delete info; - info = NULL; - } - - fclose(fp); - fontMetricsCache[filename] = info; - return info; -} - -int FontMetrics::getGlyphForChar(int ch) const -{ - return charToGlyphMap.get(ch); -} - -int FontMetricsSharedDefs::binarySearch(const RangeAndValueList& searchSpace, int x) -{ - // Do a binary search on the start of each range, grab the one that |x| - // falls inside. - // NOTE: This assumes searchSpace is sorted by |start|. - - int low = 0; - int high = static_cast<int>(searchSpace.size()-1); - while (low <= high) { - int mid = low + (high - low) / 2; - const RangeAndValue& range = searchSpace[mid]; - if (range.start <= x && range.end >= x) - return range.value; - - if (x < range.start) - high = mid - 1; - else - low = mid + 1; - } - - return -1; -} - -// static -int FontMetrics::getWidthForGlyph(int glyph) const -{ - return FontMetricsSharedDefs::binarySearch(glyphWidths, glyph); -} - -// static -const String* FontFallbackMetrics::lookup(const String& family, UChar character) -{ - // FontFallbackMetrics exist only during layout tests. - if (!webkit_glue::IsLayoutTestMode()) - return NULL; - - const FallbackRuleList* fallbackRules = getFallbackRules(family); - if (!fallbackRules) - return NULL; - - int fontIndex = binarySearch(*fallbackRules, character); - if (fontIndex == -1) - return NULL; - - return &fontIndexToNameMap()[fontIndex]; -} - -// static -FontFallbackMetrics::FallbackRuleList* FontFallbackMetrics::getFallbackRules(const String& family) -{ - // Build the file name for the font's fallback rules. - std::wstring filename = webkit_glue::StringToStdWString(family.lower()); - std::replace(filename.begin(), filename.end(), L' ', L'_'); - filename += L"-fallback.txt"; - - // If we have already parsed the fallback rules file, return the cached version. - typedef std::map<std::wstring, FallbackRuleList*> FontToFallbackRulesMap; - static FontToFallbackRulesMap fallbackRulesCache; - if (fallbackRulesCache.find(filename) != fallbackRulesCache.end()) - return fallbackRulesCache[filename]; - - // Open the fallback rules file for reading. - std::wstring path; - webkit_glue::GetApplicationDirectory(&path); - file_util::AppendToPath(&path, L"fonts"); - file_util::AppendToPath(&path, filename); - - FILE* fp; - fopen_s(&fp, WideToUTF8(path).c_str(), "r"); - - FallbackRuleList* rulesList = NULL; - - if (!fp) { - LOG_ERROR("FontFallbackMetrics::lookup: no fallback rules file: '%S'", - path.c_str()); - } else { - // Parse and close the fallback rules file. - rulesList = new FallbackRuleList; - bool successfullyParsed = parseRulesFile(fp, rulesList); - fclose(fp); - - if (!successfullyParsed) { - delete rulesList; - rulesList = NULL; - LOG_ERROR("FontFallbackMetrics::lookup: bad file format: '%S'", - path.c_str()); - ASSERT_NOT_REACHED(); - } - } - - fallbackRulesCache[filename] = rulesList; - return rulesList; -} - -// static -bool FontFallbackMetrics::parseRulesFile(FILE* fp, FontFallbackMetrics::FallbackRuleList* fallbackRules) -{ - int numFonts; - if (fscanf_s(fp, "numFonts = %d\n", &numFonts) != 1) - return false; - - // Extract all the fonts from the file, and map them to an entry in - // fontIndexToNameMap(). (Saves space by not duplicating font names) - std::map<int, int> localFontIndexToGlobalIndexMap; - for (int i = 0; i < numFonts; ++i) { - int fontIndex; - if (fscanf_s(fp, "%d = ", &fontIndex) != 1) - return false; - // use fgets instead of fscanf_s to read the font name, - // since it may contain spaces. - const unsigned kFontNameBufSize = 80; - char fontNameBuf[kFontNameBufSize]; - if (!fgets(fontNameBuf, kFontNameBufSize, fp)) - return false; - - // Strip the newline - String fontName(fontNameBuf, strlen(fontNameBuf) - 1); - localFontIndexToGlobalIndexMap[fontIndex] = getFontIndex(fontName); - } - - int numRules; - if (fscanf_s(fp, "numRules = %d\n", &numRules) != 1) - return false; - - for (int i = 0; i < numRules; ++i) { - FontMetricsSharedDefs::RangeAndValue rule; - int localFontIndex; - if (fscanf_s(fp, "[%d,%d] = %d\n", - &rule.start, &rule.end, &localFontIndex) != 3) { - return false; - } - // Set the font index that it references. - rule.value = localFontIndexToGlobalIndexMap[localFontIndex]; - fallbackRules->append(rule); - } - - return true; -} - -// static -FontFallbackMetrics::FontNameMap& FontFallbackMetrics::fontIndexToNameMap() -{ - static FontNameMap map; - return map; -} - -// static -int FontFallbackMetrics::getFontIndex(const String& family) -{ - FontNameMap& indexToFontMap = fontIndexToNameMap(); - - for (size_t i = 0; i < indexToFontMap.size(); ++i) { - if (indexToFontMap[i] == family) - return i; - } - indexToFontMap.append(family); - return indexToFontMap.size() - 1; -} - -} // namespace WebCore diff --git a/webkit/port/platform/FontMetrics.h b/webkit/port/platform/FontMetrics.h deleted file mode 100644 index e65800b..0000000 --- a/webkit/port/platform/FontMetrics.h +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright 2008, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// This file handles reading in the font metric data from the Mac version of -// DumpRenderTree. We use the sizing info from the Mac so that we can match -// the layout tests. - -#ifndef FontMetrics_H__ -#define FontMetrics_H__ - -#include <wtf/Vector.h> -#include <wtf/HashMap.h> -#include "PlatformString.h" - -namespace WebCore { - -// The following namespace holds definitions shared by -// FontMetrics and FontFallbackMetrics -namespace FontMetricsSharedDefs { - -struct RangeAndValue { - int start, end; - int value; -}; - -typedef Vector<RangeAndValue> RangeAndValueList; - -// Return V.value such that x >= V.start && x <= V.end [for V in searchSpace]. -// Expects searchSpace to be sorted ascending on RangeAndValue.start. -// If no such V exists, returns -1. -int binarySearch(const RangeAndValueList& searchSpace, int x); - -} // namespace FontMetricsSharedDefs - -class FontMetrics { -public: - // Returns the font metrics for the given font family and attributes. - // The pointer returned is owned by the FontMetrics module, and should - // not be deleted or modified by the caller. - static const FontMetrics* lookup(const String& family, - bool bold, - bool italic); - - // Returns the glyph for the given character, or 0 if not found. - int getGlyphForChar(int ch) const; - - // Returns the unscaled width of the given glyph, or -1 if not found. - int getWidthForGlyph(int glyph) const; - - String family; - float syntheticBoldOffset; - bool isSystemFont; - - // The scaling factor of the metrics. - // metric/unitsPerEm * pointSize = pixel size of the metric. - int unitsPerEm; - - // The following values should be divided by unitsPerEm to get their - // size as a fraction of the font point size. - int ascent; - int descent; - int lineGap; - int xHeight; - -private: - static bool parseFontMetricsFile(FILE* fp, FontMetrics* info); - - // To save space, Glyph widths are grouped into ranges of consecutive - // glyphs that share the same width. This mostly matters for the glyphs - // from 1000-65535 in most fonts. - typedef FontMetricsSharedDefs::RangeAndValue GlyphRange; - - typedef Vector<GlyphRange> GlyphWidthMap; - typedef HashMap<int, int> CharToGlyphMap; - - GlyphWidthMap glyphWidths; - CharToGlyphMap charToGlyphMap; -}; - -class FontFallbackMetrics { -public: - // Returns the font family to use as fallback for |family| when drawing - // character |character|, or NULL. - // This is used when in layout-test mode to simulate safari-mac's - // font fallback. - static const String* lookup(const String& family, UChar character); - -private: - typedef Vector<FontMetricsSharedDefs::RangeAndValue> FallbackRuleList; - - static bool parseRulesFile(FILE* fp, FallbackRuleList* fallbackRules); - - // Returns the list of fonts to fallback per character. - // Or returns NULL if no rules could be be found. - static FallbackRuleList* getFallbackRules(const String& family); - - // Returns a numeric name for "family" - // (corresponding to fontIndexToNameMap()[i]) - static int getFontIndex(const String& family); - - typedef Vector<String> FontNameMap; - static FontNameMap& fontIndexToNameMap(); -}; - -} // namespace WebCore - -#endif // FontMetrics_H__ diff --git a/webkit/port/platform/graphics/FontCacheWin.cpp b/webkit/port/platform/graphics/FontCacheWin.cpp index 8a4a5a2..24b5b8a 100644 --- a/webkit/port/platform/graphics/FontCacheWin.cpp +++ b/webkit/port/platform/graphics/FontCacheWin.cpp @@ -28,7 +28,6 @@ #include "config.h" #include "FontCache.h" -#include "FontMetrics.h" #include "Font.h" #include "SimpleFontData.h" #include "StringHash.h" @@ -316,24 +315,6 @@ const SimpleFontData* FontCache::getFontDataForCharacters(const Font& font, const UChar* characters, int length) { - // Use Safari mac's font-fallback mechanism when in layout test mode. - if (webkit_glue::IsLayoutTestMode() && length == 1) { - // Get the family name for the font - String origFamily = - font.primaryFont()->platformData().overrideFontMetrics()->family; - - const String* fallbackFamily = - FontFallbackMetrics::lookup(origFamily, characters[0]); - - if (fallbackFamily) { - FontPlatformData* platformData = getCachedFontPlatformData( - font.fontDescription(), *fallbackFamily); - if (platformData) { - return new SimpleFontData(*platformData); - } - } - } - // TODO(jungshik) : Consider passing fontDescription.dominantScript() // to GetFallbackFamily here along with the corresponding change // in base/gfx. @@ -445,7 +426,7 @@ const SimpleFontData* FontCache::getFontDataForCharacters(const Font& font, if (langFontLink->MapFont(hdc, actualCodePages, characters[0], &result) == S_OK) { // This font will have to be deleted using the IMLangFontLink2 // rather than the normal way. - fontData = new SimpleFontData(FontPlatformData(result, 0, 0, true)); + fontData = new SimpleFontData(FontPlatformData(result, 0, true)); } } @@ -501,9 +482,6 @@ FontPlatformData* FontCache::getSimilarFontPlatformData(const Font& font) FontPlatformData* FontCache::getLastResortFallbackFont( const FontDescription& description) { - if (webkit_glue::IsLayoutTestMode()) - return getCachedFontPlatformData(description, AtomicString("Times")); - FontDescription::GenericFamilyType generic = description.genericFamily(); // TODO(jungshik): Mapping webkit generic to gfx::GenericFamilyType needs to be // more intelligent and the mapping function should be added to webkit_glue. @@ -606,20 +584,9 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD if (!hfont) return 0; - const FontMetrics* overrideFontMetrics = NULL; - - if (webkit_glue::IsLayoutTestMode()) { - // In layout-test mode, we have a font IFF it exists in our font size - // cache. We want to ignore the existence/absence of the font in the - // system. - overrideFontMetrics = FontMetrics::lookup(family, - fontDescription.bold(), - fontDescription.italic()); - if (!overrideFontMetrics) { - DeleteObject(hfont); - return 0; - } - } else if (!equalIgnoringCase(family, winName)) { + // TODO(pamg): Do we need to use predefined fonts "guaranteed" to exist + // when we're running in layout-test mode? + if (!equalIgnoringCase(family, winName)) { // For CJK fonts with both English and native names, // GetTextFace returns a native name under the font's "locale" // and an English name under other locales regardless of @@ -636,7 +603,6 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD return new FontPlatformData(hfont, fontDescription.computedPixelSize(), - overrideFontMetrics, false); } diff --git a/webkit/port/platform/graphics/FontCustomPlatformData.cpp b/webkit/port/platform/graphics/FontCustomPlatformData.cpp index 10afecf..4c71f38 100644 --- a/webkit/port/platform/graphics/FontCustomPlatformData.cpp +++ b/webkit/port/platform/graphics/FontCustomPlatformData.cpp @@ -33,7 +33,7 @@ FontCustomPlatformData::~FontCustomPlatformData() FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, bool italic) { - return FontPlatformData(m_font, size, 0, false); + return FontPlatformData(m_font, size, false); } FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer) diff --git a/webkit/port/platform/graphics/FontPlatformData.h b/webkit/port/platform/graphics/FontPlatformData.h index 9a363ea..61d45ac 100644 --- a/webkit/port/platform/graphics/FontPlatformData.h +++ b/webkit/port/platform/graphics/FontPlatformData.h @@ -32,7 +32,6 @@ typedef struct HFONT__ *HFONT; namespace WebCore { class FontDescription; -class FontMetrics; class FontPlatformData { @@ -53,19 +52,16 @@ public: FontPlatformData(Deleted) : m_font(RefCountedHFONT::createDeleted()) , m_size(-1) - , m_overrideFontMetrics(0) , m_isMLangFont(false) {} FontPlatformData() : m_font(0) , m_size(0) - , m_overrideFontMetrics(0) , m_isMLangFont(false) {} FontPlatformData(HFONT hfont, float size, - const FontMetrics* overrideFontMetrics, bool isMLangFont); FontPlatformData(float size, bool bold, bool oblique); @@ -73,7 +69,6 @@ public: HFONT hfont() const { return m_font ? m_font->hfont() : 0; } float size() const { return m_size; } - const FontMetrics* overrideFontMetrics() const { return m_overrideFontMetrics; } bool isMLangFont() const { return m_isMLangFont; } unsigned hash() const @@ -118,13 +113,6 @@ private: RefPtr<RefCountedHFONT> m_font; float m_size; // Point size of the font in pixels. - // Used by layout tests. Contains cached font size information from a run of - // DumpRenderTree on the Mac. This is only non-NULL during layout test mode, - // and if it exists, means we should use these metrics instead of - // system-supplied ones. We do this so that we can exactly match the - // layout test references as far as how text is laid out. - const FontMetrics* m_overrideFontMetrics; - bool m_isMLangFont; }; diff --git a/webkit/port/platform/graphics/FontPlatformDataWin.cpp b/webkit/port/platform/graphics/FontPlatformDataWin.cpp index b28b770..53ade3e 100644 --- a/webkit/port/platform/graphics/FontPlatformDataWin.cpp +++ b/webkit/port/platform/graphics/FontPlatformDataWin.cpp @@ -29,11 +29,9 @@ namespace WebCore { FontPlatformData::FontPlatformData(HFONT font, float size, - const FontMetrics* overrideFontMetrics, bool isMLangFont) : m_font(RefCountedHFONT::create(font)) , m_size(size) - , m_overrideFontMetrics(overrideFontMetrics) , m_isMLangFont(isMLangFont) { } @@ -43,7 +41,6 @@ FontPlatformData::FontPlatformData(HFONT font, float size, FontPlatformData::FontPlatformData(float size, bool bold, bool oblique) : m_size(size) , m_font(0) - , m_overrideFontMetrics(0) { } diff --git a/webkit/port/platform/graphics/GlyphPageTreeNodeWin.cpp b/webkit/port/platform/graphics/GlyphPageTreeNodeWin.cpp index 70ceaac..e32d1ac 100644 --- a/webkit/port/platform/graphics/GlyphPageTreeNodeWin.cpp +++ b/webkit/port/platform/graphics/GlyphPageTreeNodeWin.cpp @@ -28,7 +28,6 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "config.h" -#include "FontMetrics.h" #include <windows.h> #include <vector> @@ -58,25 +57,6 @@ static bool FillBMPGlyphs(UChar* buffer, const SimpleFontData* fontData, bool recurse) { - const FontMetrics* metrics = fontData->platformData().overrideFontMetrics(); - if (metrics) { - // We have cached metrics available from a run of Apple's - // DumpRenderTree. We use these during layout tests instead of the - // system-supplied metrics so that we can match their font size output. - bool have_glyphs = false; - for (unsigned i = 0; i < GlyphPage::size; i++) { - int glyph = metrics->getGlyphForChar(buffer[i]); - if (glyph) { - have_glyphs = true; - page->setGlyphDataForIndex(i, glyph, fontData); - } else { - // Font.cpp relies on !GlyphData.fontData for non-existant glyphs. - page->setGlyphDataForIndex(i, 0, 0); - } - } - return have_glyphs; - } - HDC dc = GetDC((HWND)0); HGDIOBJ old_font = SelectObject(dc, fontData->m_font.hfont()); diff --git a/webkit/port/platform/graphics/SimpleFontDataWin.cpp b/webkit/port/platform/graphics/SimpleFontDataWin.cpp index df1be50..bbe1d3a 100644 --- a/webkit/port/platform/graphics/SimpleFontDataWin.cpp +++ b/webkit/port/platform/graphics/SimpleFontDataWin.cpp @@ -30,7 +30,6 @@ #include "Font.h" #include "FontCache.h" #include "SimpleFontData.h" -#include "FontMetrics.h" #include "FloatRect.h" #include "FontDescription.h" #include <wtf/MathExtras.h> @@ -70,54 +69,19 @@ void SimpleFontData::platformInit() m_avgCharWidth = tm.tmAveCharWidth; m_maxCharWidth = tm.tmMaxCharWidth; - if (!m_font.overrideFontMetrics()) { - m_ascent = tm.tmAscent; - m_descent = tm.tmDescent; - m_lineGap = tm.tmExternalLeading; - m_xHeight = m_ascent * 0.56f; // Best guess for xHeight for non-Truetype fonts. - - OUTLINETEXTMETRIC otm; - if (GetOutlineTextMetrics(dc, sizeof(otm), &otm) > 0) { - // This is a TrueType font. We might be able to get an accurate xHeight. - GLYPHMETRICS gm = {0}; - MAT2 mat = {{0, 1}, {0, 0}, {0, 0}, {0, 1}}; // The identity matrix. - DWORD len = GetGlyphOutlineW(dc, 'x', GGO_METRICS, &gm, 0, 0, &mat); - if (len != GDI_ERROR && gm.gmBlackBoxY > 0) - m_xHeight = static_cast<float>(gm.gmBlackBoxY); - } - } else { - // We have cached metrics available from a run of Apple's DumpRenderTree. - // We use these instead of the system metrics, and scale them the same - // way that Apple does. - - const FontMetrics* metrics = m_font.overrideFontMetrics(); - int unitsPerEm = metrics->unitsPerEm; - float pointSize = m_font.size(); - float fAscent = scaleEmToUnits(metrics->ascent, unitsPerEm) * pointSize; - float fDescent = scaleEmToUnits(metrics->descent, unitsPerEm) * pointSize; - float fLineGap = scaleEmToUnits(metrics->lineGap, unitsPerEm) * pointSize; - float fXHeight = scaleEmToUnits(metrics->xHeight, unitsPerEm) * pointSize; - - m_isSystemFont = metrics->isSystemFont; - - // The following comment and code is from FontDataMac.mm (since we're - // using their metrics, we need to adjust them the same way they do): - - // We need to adjust Times, Helvetica, and Courier to closely match the - // vertical metrics of their Microsoft counterparts that are the de facto - // web standard. The AppKit adjustment of 20% is too big and is - // incorrectly added to line spacing, so we use a 15% adjustment instead - // and add it to the ascent. - if (equalIgnoringCase(metrics->family, "Times") || - equalIgnoringCase(metrics->family, "Helvetica") || - equalIgnoringCase(metrics->family, "Courier")) { - fAscent += floorf(((fAscent + fDescent) * 0.15f) + 0.5f); - } - - m_ascent = lroundf(fAscent); - m_descent = lroundf(fDescent); - m_lineGap = lroundf(fLineGap); - m_xHeight = fXHeight; + m_ascent = tm.tmAscent; + m_descent = tm.tmDescent; + m_lineGap = tm.tmExternalLeading; + m_xHeight = m_ascent * 0.56f; // Best guess for xHeight for non-Truetype fonts. + + OUTLINETEXTMETRIC otm; + if (GetOutlineTextMetrics(dc, sizeof(otm), &otm) > 0) { + // This is a TrueType font. We might be able to get an accurate xHeight. + GLYPHMETRICS gm = {0}; + MAT2 mat = {{0, 1}, {0, 0}, {0, 0}, {0, 1}}; // The identity matrix. + DWORD len = GetGlyphOutlineW(dc, 'x', GGO_METRICS, &gm, 0, 0, &mat); + if (len != GDI_ERROR && gm.gmBlackBoxY > 0) + m_xHeight = static_cast<float>(gm.gmBlackBoxY); } m_lineSpacing = m_ascent + m_descent + m_lineGap; @@ -168,7 +132,6 @@ SimpleFontData* SimpleFontData::smallCapsFontData(const FontDescription& fontDes HFONT hfont = CreateFontIndirect(&winfont); m_smallCapsFontData = new SimpleFontData(FontPlatformData(hfont, smallCapsSize, - m_font.overrideFontMetrics(), false)); } return m_smallCapsFontData; @@ -234,31 +197,6 @@ void SimpleFontData::determinePitch() float SimpleFontData::platformWidthForGlyph(Glyph glyph) const { - const FontMetrics* metrics = m_font.overrideFontMetrics(); - if (metrics && glyph) { - // We have cached metrics available from a run of Apple's DumpRenderTree. - // We use these during layout tests instead of the system-supplied - // metrics so that we can match their font size output. - - int width = metrics->getWidthForGlyph(glyph); - ASSERT(width != -1); - float pointSize = m_font.size(); - float fWidth = scaleEmToUnits(width, metrics->unitsPerEm) * pointSize; - float result = fWidth + metrics->syntheticBoldOffset; - - // Don't round for the system font, because Apple doesn't. - if (!m_isSystemFont) - result = roundf(result); - -#ifdef SUPER_VERBOSE_FONT_DEBUGGING - fprintf(stderr, "GLYPH %s-%d: %d/%d*%f = %f + %d = %f\n", - metrics->family.ascii().data(), glyph, width, metrics->unitsPerEm, - pointSize, fWidth, metrics->syntheticBoldOffset, result); -#endif - - return result; - } - HDC dc = GetDC(0); HGDIOBJ oldFont = SelectObject(dc, m_font.hfont()); |