diff options
Diffstat (limited to 'webkit/port/platform/graphics/chromium')
30 files changed, 0 insertions, 4962 deletions
diff --git a/webkit/port/platform/graphics/chromium/FontCacheChromiumWin.cpp b/webkit/port/platform/graphics/chromium/FontCacheChromiumWin.cpp deleted file mode 100644 index ccbd8447..0000000 --- a/webkit/port/platform/graphics/chromium/FontCacheChromiumWin.cpp +++ /dev/null @@ -1,635 +0,0 @@ -/* - * Copyright (C) 2006, 2007 Apple 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: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "FontCache.h" - -#include "ChromiumBridge.h" -#include "Font.h" -#include "FontUtilsChromiumWin.h" -#include "HashMap.h" -#include "HashSet.h" -#include "SimpleFontData.h" -#include "StringHash.h" -#include <unicode/uniset.h> - -#include <windows.h> -#include <objidl.h> -#include <mlang.h> - -using std::min; - -namespace WebCore -{ - -void FontCache::platformInit() -{ - // Not needed on Windows. -} - -// FIXME(jungshik) : consider adding to WebKit String class -static bool isStringASCII(const String& s) -{ - for (int i = 0; i < static_cast<int>(s.length()); ++i) { - if (s[i] > 0x7f) - return false; - } - return true; -} - -// When asked for a CJK font with a native name under a non-CJK locale or -// asked for a CJK font with a Romanized name under a CJK locale, -// |GetTextFace| (after |CreateFont*|) returns a 'bogus' value (e.g. Arial). -// This is not consistent with what MSDN says !! -// Therefore, before we call |CreateFont*|, we have to map a Romanized name to -// the corresponding native name under a CJK locale and vice versa -// under a non-CJK locale. -// See the corresponding gecko bugs at -// https://bugzilla.mozilla.org/show_bug.cgi?id=373952 -// https://bugzilla.mozilla.org/show_bug.cgi?id=231426 -static bool LookupAltName(const String& name, String& altName) -{ - struct FontCodepage { - WCHAR *name; - int codePage; - }; - - struct NamePair { - WCHAR *name; - FontCodepage altNameCp; - }; - - // FIXME(jungshik) : This list probably covers 99% of cases. - // To cover the remaining 1% and cut down the file size, - // consider accessing 'NAME' table of a truetype font - // using |GetFontData| and caching the mapping. - // 932 : Japanese, 936 : Simp. Chinese, 949 : Korean, 950 : Trad. Chinese - // In the table below, the ASCII keys are all lower-cased for - // case-insensitive matching. - static const NamePair namePairs[] = { - // MS Pゴシック, MS PGothic - {L"\xFF2D\xFF33 \xFF30\x30B4\x30B7\x30C3\x30AF", {L"MS PGothic", 932}}, - {L"ms pgothic", {L"\xFF2D\xFF33 \xFF30\x30B4\x30B7\x30C3\x30AF", 932}}, - // MS P明朝, MS PMincho - {L"\xFF2D\xFF33 \xFF30\x660E\x671D", {L"MS PMincho", 932}}, - {L"ms pmincho", {L"\xFF2D\xFF33 \xFF30\x660E\x671D", 932}}, - // MSゴシック, MS Gothic - {L"\xFF2D\xFF33 \x30B4\x30B7\x30C3\x30AF", {L"MS Gothic", 932}}, - {L"ms gothic", {L"\xFF2D\xFF33 \x30B4\x30B7\x30C3\x30AF", 932}}, - // MS 明朝, MS Mincho - {L"\xFF2D\xFF33 \x660E\x671D", {L"MS Mincho", 932}}, - {L"ms mincho", {L"\xFF2D\xFF33 \x660E\x671D", 932}}, - // メイリオ, Meiryo - {L"\x30E1\x30A4\x30EA\x30AA", {L"Meiryo", 932}}, - {L"meiryo", {L"\x30E1\x30A4\x30EA\x30AA", 932}}, - // 바탕, Batang - {L"\xBC14\xD0D5", {L"Batang", 949}}, - {L"batang", {L"\xBC14\xD0D5", 949}}, - // 바탕체, Batangche - {L"\xBC14\xD0D5\xCCB4", {L"Batangche", 949}}, - {L"batangche", {L"\xBC14\xD0D5\xCCB4", 949}}, - // 굴림, Gulim - {L"\xAD74\xB9BC", {L"Gulim", 949}}, - {L"gulim", {L"\xAD74\xB9BC", 949}}, - // 굴림체, Gulimche - {L"\xAD74\xB9BC\xCCB4", {L"Gulimche", 949}}, - {L"gulimche", {L"\xAD74\xB9BC\xCCB4", 949}}, - // 돋움, Dotum - {L"\xB3CB\xC6C0", {L"Dotum", 949}}, - {L"dotum", {L"\xB3CB\xC6C0", 949}}, - // 돋움체, Dotumche - {L"\xB3CB\xC6C0\xCCB4", {L"Dotumche", 949}}, - {L"dotumche", {L"\xB3CB\xC6C0\xCCB4", 949}}, - // 궁서, Gungsuh - {L"\xAD81\xC11C", {L"Gungsuh", 949}}, - {L"gungsuh", {L"\xAD81\xC11C", 949}}, - // 궁서체, Gungsuhche - {L"\xAD81\xC11C\xCCB4", {L"Gungsuhche", 949}}, - {L"gungsuhche", {L"\xAD81\xC11C\xCCB4", 949}}, - // 맑은 고딕, Malgun Gothic - {L"\xB9D1\xC740 \xACE0\xB515", {L"Malgun Gothic", 949}}, - {L"malgun gothic", {L"\xB9D1\xC740 \xACE0\xB515", 949}}, - // 宋体, SimSun - {L"\x5B8B\x4F53", {L"SimSun", 936}}, - {L"simsun", {L"\x5B8B\x4F53", 936}}, - // 黑体, SimHei - {L"\x9ED1\x4F53", {L"SimHei", 936}}, - {L"simhei", {L"\x9ED1\x4F53", 936}}, - // 新宋体, NSimSun - {L"\x65B0\x5B8B\x4F53", {L"NSimSun", 936}}, - {L"nsimsun", {L"\x65B0\x5B8B\x4F53", 936}}, - // 微软雅黑, Microsoft Yahei - {L"\x5FAE\x8F6F\x96C5\x9ED1", {L"Microsoft Yahei", 936}}, - {L"microsoft yahei", {L"\x5FAE\x8F6F\x96C5\x9ED1", 936}}, - // 仿宋, FangSong - {L"\x4EFF\x5B8B", {L"FangSong", 936}}, - {L"fangsong", {L"\x4EFF\x5B8B", 936}}, - // 楷体, KaiTi - {L"\x6977\x4F53", {L"KaiTi", 936}}, - {L"kaiti", {L"\x6977\x4F53", 936}}, - // 仿宋_GB2312, FangSong_GB2312 - {L"\x4EFF\x5B8B_GB2312", {L"FangSong_GB2312", 936}}, - {L"fangsong_gb2312", {L"\x4EFF\x5B8B_gb2312", 936}}, - // 楷体_GB2312, KaiTi_GB2312 - {L"\x6977\x4F53", {L"KaiTi_GB2312", 936}}, - {L"kaiti_gb2312", {L"\x6977\x4F53_gb2312", 936}}, - // 新細明體, PMingLiu - {L"\x65B0\x7D30\x660E\x9AD4", {L"PMingLiu", 950}}, - {L"pmingliu", {L"\x65B0\x7D30\x660E\x9AD4", 950}}, - // 細明體, MingLiu - {L"\x7D30\x660E\x9AD4", {L"MingLiu", 950}}, - {L"mingliu", {L"\x7D30\x660E\x9AD4", 950}}, - // 微軟正黑體, Microsoft JhengHei - {L"\x5FAE\x8EDF\x6B63\x9ED1\x9AD4", {L"Microsoft JhengHei", 950}}, - {L"microsoft jhengHei", {L"\x5FAE\x8EDF\x6B63\x9ED1\x9AD4", 950}}, - // 標楷體, DFKai-SB - {L"\x6A19\x6977\x9AD4", {L"DFKai-SB", 950}}, - {L"dfkai-sb", {L"\x6A19\x6977\x9AD4", 950}}, - // WenQuanYi Zen Hei - {L"\x6587\x6cc9\x9a5b\x6b63\x9ed1", {L"WenQuanYi Zen Hei", 950}}, - {L"wenquanyi zen hei", {L"\x6587\x6cc9\x9a5b\x6b63\x9ed1", 950}}, - // WenQuanYi Zen Hei - {L"\x6587\x6cc9\x9a7f\x6b63\x9ed1", {L"WenQuanYi Zen Hei", 936}}, - {L"wenquanyi zen hei", {L"\x6587\x6cc9\x9a7f\x6b63\x9ed1", 936}}, - // AR PL ShanHeiSun Uni, - {L"\x6587\x9f0e\x0050\x004c\x7d30\x4e0a\x6d77\x5b8b\x0055\x006e\x0069", - {L"AR PL ShanHeiSun Uni", 950}}, - {L"ar pl shanheisun uni", - {L"\x6587\x9f0e\x0050\x004c\x7d30\x4e0a\x6d77\x5b8b\x0055\x006e\x0069", 950}}, - // AR PL ShanHeiSun Uni, - {L"\x6587\x9f0e\x0050\x004c\x7ec6\x4e0a\x6d77\x5b8b\x0055\x006e\x0069", - {L"AR PL ShanHeiSun Uni", 936}}, - {L"ar pl shanheisun uni", - {L"\x6587\x9f0e\x0050\x004c\x7ec6\x4e0a\x6d77\x5b8b\x0055\x006e\x0069", 936}}, - // AR PL ZenKai Uni - // Traditional Chinese (950) and Simplified Chinese (936) names are - // identical. - {L"\x6587\x0050\x004C\x4E2D\x6977\x0055\x006E\x0069", {L"AR PL ZenKai Uni", 950}}, - {L"ar pl zenkai uni", {L"\x6587\x0050\x004C\x4E2D\x6977\x0055\x006E\x0069", 950}}, - {L"\x6587\x0050\x004C\x4E2D\x6977\x0055\x006E\x0069", {L"AR PL ZenKai Uni", 936}}, - {L"ar pl zenkai uni", {L"\x6587\x0050\x004C\x4E2D\x6977\x0055\x006E\x0069", 936}}, - }; - - typedef HashMap<String, const FontCodepage*> NameMap; - static NameMap* fontNameMap = NULL; - - if (!fontNameMap) { - size_t numElements = sizeof(namePairs) / sizeof(NamePair); - fontNameMap = new NameMap; - for (size_t i = 0; i < numElements; ++i) - fontNameMap->set(String(namePairs[i].name), &(namePairs[i].altNameCp)); - } - - bool isAscii = false; - String n; - // use |lower| only for ASCII names - // For non-ASCII names, we don't want to invoke an expensive - // and unnecessary |lower|. - if (isStringASCII(name)) { - isAscii = true; - n = name.lower(); - } else - n = name; - - NameMap::iterator iter = fontNameMap->find(n); - if (iter == fontNameMap->end()) - return false; - - static int systemCp = ::GetACP(); - int fontCp = iter->second->codePage; - - if ((isAscii && systemCp == fontCp) || (!isAscii && systemCp != fontCp)) { - altName = String(iter->second->name); - return true; - } - - return false; -} - -static HFONT createFontIndirectAndGetWinName(const String& family, - LOGFONT* winfont, String* winName) -{ - int len = min(static_cast<int>(family.length()), LF_FACESIZE - 1); - memcpy(winfont->lfFaceName, family.characters(), len * sizeof(WORD)); - winfont->lfFaceName[len] = '\0'; - - HFONT hfont = CreateFontIndirect(winfont); - if (!hfont) - return NULL; - - HDC dc = GetDC(0); - HGDIOBJ oldFont = static_cast<HFONT>(SelectObject(dc, hfont)); - WCHAR name[LF_FACESIZE]; - unsigned resultLength = GetTextFace(dc, LF_FACESIZE, name); - if (resultLength > 0) - resultLength--; // ignore the null terminator - - SelectObject(dc, oldFont); - ReleaseDC(0, dc); - *winName = String(name, resultLength); - return hfont; -} - -// This maps font family names to their repertoires of supported Unicode -// characters. Because it's family names rather than font faces we use -// as keys, there might be edge cases where one face of a font family -// has a different repertoire from another face of the same family. -typedef HashMap<const wchar_t*, UnicodeSet*> FontCmapCache; - -static bool fontContainsCharacter(const FontPlatformData* font_data, - const wchar_t* family, UChar32 character) -{ - // TODO(jungshik) : For non-BMP characters, GetFontUnicodeRanges is of - // no use. We have to read directly from the cmap table of a font. - // Return true for now. - if (character > 0xFFFF) - return true; - - // This cache is just leaked on shutdown. - static FontCmapCache* fontCmapCache = NULL; - if (!fontCmapCache) - fontCmapCache = new FontCmapCache; - - HashMap<const wchar_t*, UnicodeSet*>::iterator it = - fontCmapCache->find(family); - if (it != fontCmapCache->end()) - return it->second->contains(character); - - HFONT hfont = font_data->hfont(); - HDC hdc = GetDC(0); - HGDIOBJ oldFont = static_cast<HFONT>(SelectObject(hdc, hfont)); - int count = GetFontUnicodeRanges(hdc, 0); - if (count == 0 && ChromiumBridge::ensureFontLoaded(hfont)) - count = GetFontUnicodeRanges(hdc, 0); - if (count == 0) { - ASSERT_NOT_REACHED(); - SelectObject(hdc, oldFont); - ReleaseDC(0, hdc); - return true; - } - - static Vector<char, 512> glyphsetBuffer; - glyphsetBuffer.resize(GetFontUnicodeRanges(hdc, 0)); - GLYPHSET* glyphset = reinterpret_cast<GLYPHSET*>(glyphsetBuffer.data()); - // In addition, refering to the OS/2 table and converting the codepage list - // to the coverage map might be faster. - count = GetFontUnicodeRanges(hdc, glyphset); - ASSERT(count > 0); - SelectObject(hdc, oldFont); - ReleaseDC(0, hdc); - - // TODO(jungshik) : consider doing either of the following two: - // 1) port back ICU 4.0's faster look-up code for UnicodeSet - // 2) port Mozilla's CompressedCharMap or gfxSparseBitset - unsigned i = 0; - UnicodeSet* cmap = new UnicodeSet; - while (i < glyphset->cRanges) { - WCHAR start = glyphset->ranges[i].wcLow; - cmap->add(start, start + glyphset->ranges[i].cGlyphs - 1); - i++; - } - cmap->freeze(); - // We don't lowercase |family| because all of them are under our control - // and they're already lowercased. - fontCmapCache->set(family, cmap); - return cmap->contains(character); -} - -// Given the desired base font, this will create a SimpleFontData for a specific -// font that can be used to render the given range of characters. -const SimpleFontData* FontCache::getFontDataForCharacters(const Font& font, - const UChar* characters, - int length) -{ - // TODO(jungshik) : Consider passing fontDescription.dominantScript() - // to GetFallbackFamily here. - FontDescription fontDescription = font.fontDescription(); - UChar32 c; - UScriptCode script; - const wchar_t* family = getFallbackFamily(characters, length, - fontDescription.genericFamily(), &c, &script); - FontPlatformData* data = NULL; - if (family) { - data = getCachedFontPlatformData(font.fontDescription(), - AtomicString(family, wcslen(family)), - false); - } - - // Last resort font list : PanUnicode. CJK fonts have a pretty - // large repertoire. Eventually, we need to scan all the fonts - // on the system to have a Firefox-like coverage. - // Make sure that all of them are lowercased. - const static wchar_t* const cjkFonts[] = { - L"arial unicode ms", - L"ms pgothic", - L"simsun", - L"gulim", - L"pmingliu", - L"wenquanyi zen hei", // partial CJK Ext. A coverage but more - // widely known to Chinese users. - L"ar pl shanheisun uni", - L"ar pl zenkai uni", - L"han nom a", // Complete CJK Ext. A coverage - L"code2000", // Complete CJK Ext. A coverage - // CJK Ext. B fonts are not listed here because it's of no use - // with our current non-BMP character handling because we use - // Uniscribe for it and that code path does not go through here. - }; - - const static wchar_t* const commonFonts[] = { - L"tahoma", - L"arial unicode ms", - L"lucida sans unicode", - L"microsoft sans serif", - L"palatino linotype", - // Four fonts below (and code2000 at the end) are not from MS, but - // once installed, cover a very wide range of characters. - L"freeserif", - L"freesans", - L"gentium", - L"gentiumalt", - L"ms pgothic", - L"simsun", - L"gulim", - L"pmingliu", - L"code2000", - }; - - const wchar_t* const* panUniFonts = NULL; - int numFonts = 0; - if (script == USCRIPT_HAN) { - panUniFonts = cjkFonts; - numFonts = ARRAYSIZE(cjkFonts); - } else { - panUniFonts = commonFonts; - numFonts = ARRAYSIZE(commonFonts); - } - // Font returned from GetFallbackFamily may not cover |characters| - // because it's based on script to font mapping. This problem is - // critical enough for non-Latin scripts (especially Han) to - // warrant an additional (real coverage) check with fontCotainsCharacter. - int i; - for (i = 0; (!data || !fontContainsCharacter(data, family, c)) - && i < numFonts; ++i) { - family = panUniFonts[i]; - data = getCachedFontPlatformData(font.fontDescription(), - AtomicString(family, wcslen(family))); - } - if (i < numFonts) // we found the font that covers this character ! - return getCachedFontData(data); - - return NULL; - -} - -const AtomicString& FontCache::alternateFamilyName(const AtomicString& familyName) -{ - // Note that mapping to Courier is removed because - // because it's a bitmap font on Windows. - // Alias Courier -> Courier New - static AtomicString courier("Courier"), courierNew("Courier New"); - if (equalIgnoringCase(familyName, courier)) - return courierNew; - - // Alias Times <-> Times New Roman. - static AtomicString times("Times"), timesNewRoman("Times New Roman"); - if (equalIgnoringCase(familyName, times)) - return timesNewRoman; - if (equalIgnoringCase(familyName, timesNewRoman)) - return times; - - // Alias Helvetica <-> Arial - static AtomicString arial("Arial"), helvetica("Helvetica"); - if (equalIgnoringCase(familyName, helvetica)) - return arial; - if (equalIgnoringCase(familyName, arial)) - return helvetica; - - // We block bitmap fonts altogether so that we have to - // alias MS Sans Serif (bitmap font) -> Microsoft Sans Serif (truetype font) - static AtomicString msSans("MS Sans Serif"); - static AtomicString microsoftSans("Microsoft Sans Serif"); - if (equalIgnoringCase(familyName, msSans)) - return microsoftSans; - - // Alias MS Serif (bitmap) -> Times New Roman (truetype font). There's no - // 'Microsoft Sans Serif-equivalent' for Serif. - static AtomicString msSerif("MS Serif"); - if (equalIgnoringCase(familyName, msSerif)) - return timesNewRoman; - - // TODO(jungshik) : should we map 'system' to something ('Tahoma') ? - return emptyAtom; -} - -FontPlatformData* FontCache::getSimilarFontPlatformData(const Font& font) -{ - return 0; -} - -FontPlatformData* FontCache::getLastResortFallbackFont( - const FontDescription& description) -{ - FontDescription::GenericFamilyType generic = description.genericFamily(); - // TODO(jungshik): Mapping webkit generic to GenericFamilyType needs to - // be more intelligent. - // This spot rarely gets reached. GetFontDataForCharacters() gets hit a lot - // more often (see TODO comment there). - const wchar_t* family = getFontFamilyForScript(description.dominantScript(), - generic); - - if (family) - return getCachedFontPlatformData(description, AtomicString(family, wcslen(family))); - - // FIXME: Would be even better to somehow get the user's default font here. - // For now we'll pick the default that the user would get without changing - // any prefs. - static AtomicString timesStr("Times New Roman"); - static AtomicString courierStr("Courier New"); - static AtomicString arialStr("Arial"); - - AtomicString& fontStr = timesStr; - if (generic == FontDescription::SansSerifFamily) - fontStr = arialStr; - else if (generic == FontDescription::MonospaceFamily) - fontStr = courierStr; - - return getCachedFontPlatformData(description, fontStr); -} - -static LONG toGDIFontWeight(FontWeight fontWeight) -{ - static LONG gdiFontWeights[] = { - FW_THIN, // FontWeight100 - FW_EXTRALIGHT, // FontWeight200 - FW_LIGHT, // FontWeight300 - FW_NORMAL, // FontWeight400 - FW_MEDIUM, // FontWeight500 - FW_SEMIBOLD, // FontWeight600 - FW_BOLD, // FontWeight700 - FW_EXTRABOLD, // FontWeight800 - FW_HEAVY // FontWeight900 - }; - return gdiFontWeights[fontWeight]; -} - -// TODO(jungshik): This may not be the best place to put this function. See -// TODO in pending/FontCache.h. -AtomicString FontCache::getGenericFontForScript(UScriptCode script, const FontDescription& description) -{ - const wchar_t* scriptFont = getFontFamilyForScript( - script, description.genericFamily()); - return scriptFont ? AtomicString(scriptFont, wcslen(scriptFont)) : emptyAtom; -} - -static void FillLogFont(const FontDescription& fontDescription, LOGFONT* winfont) -{ - // The size here looks unusual. The negative number is intentional. - // Unlike WebKit trunk, we don't multiply the size by 32. That seems to be - // some kind of artifact of their CG backend, or something. - winfont->lfHeight = -fontDescription.computedPixelSize(); - winfont->lfWidth = 0; - winfont->lfEscapement = 0; - winfont->lfOrientation = 0; - winfont->lfUnderline = false; - winfont->lfStrikeOut = false; - winfont->lfCharSet = DEFAULT_CHARSET; - winfont->lfOutPrecision = OUT_TT_ONLY_PRECIS; - winfont->lfQuality = ChromiumBridge::layoutTestMode() ? NONANTIALIASED_QUALITY - : DEFAULT_QUALITY; // Honor user's desktop settings. - winfont->lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; - winfont->lfItalic = fontDescription.italic(); - winfont->lfWeight = toGDIFontWeight(fontDescription.weight()); -} - -bool FontCache::fontExists(const FontDescription& fontDescription, const AtomicString& family) -{ - LOGFONT winfont = {0}; - FillLogFont(fontDescription, &winfont); - String winName; - HFONT hfont = createFontIndirectAndGetWinName(family, &winfont, &winName); - if (!hfont) - return false; - - DeleteObject(hfont); - if (equalIgnoringCase(family, winName)) - return true; - // 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 - // lfFaceName field of LOGFONT. As a result, we need to check - // if a font has an alternate name. If there is, we need to - // compare it with what's requested in the first place. - String altName; - return LookupAltName(family, altName) && equalIgnoringCase(altName, winName); -} - -struct TraitsInFamilyProcData { - TraitsInFamilyProcData(const AtomicString& familyName) - : m_familyName(familyName) - { - } - - const AtomicString& m_familyName; - HashSet<unsigned> m_traitsMasks; -}; - -static int CALLBACK traitsInFamilyEnumProc(CONST LOGFONT* logFont, CONST TEXTMETRIC* metrics, DWORD fontType, LPARAM lParam) -{ - TraitsInFamilyProcData* procData = reinterpret_cast<TraitsInFamilyProcData*>(lParam); - - unsigned traitsMask = 0; - traitsMask |= logFont->lfItalic ? FontStyleItalicMask : FontStyleNormalMask; - traitsMask |= FontVariantNormalMask; - LONG weight = logFont->lfWeight; - traitsMask |= weight == FW_THIN ? FontWeight100Mask : - weight == FW_EXTRALIGHT ? FontWeight200Mask : - weight == FW_LIGHT ? FontWeight300Mask : - weight == FW_NORMAL ? FontWeight400Mask : - weight == FW_MEDIUM ? FontWeight500Mask : - weight == FW_SEMIBOLD ? FontWeight600Mask : - weight == FW_BOLD ? FontWeight700Mask : - weight == FW_EXTRABOLD ? FontWeight800Mask : - FontWeight900Mask; - procData->m_traitsMasks.add(traitsMask); - return 1; -} - -void FontCache::getTraitsInFamily(const AtomicString& familyName, Vector<unsigned>& traitsMasks) -{ - HDC hdc = GetDC(0); - - LOGFONT logFont; - logFont.lfCharSet = DEFAULT_CHARSET; - unsigned familyLength = min(familyName.length(), static_cast<unsigned>(LF_FACESIZE - 1)); - memcpy(logFont.lfFaceName, familyName.characters(), familyLength * sizeof(UChar)); - logFont.lfFaceName[familyLength] = 0; - logFont.lfPitchAndFamily = 0; - - TraitsInFamilyProcData procData(familyName); - EnumFontFamiliesEx(hdc, &logFont, traitsInFamilyEnumProc, reinterpret_cast<LPARAM>(&procData), 0); - copyToVector(procData.m_traitsMasks, traitsMasks); - - ReleaseDC(0, hdc); -} - -FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family) -{ - LOGFONT winfont = {0}; - FillLogFont(fontDescription, &winfont); - - // Windows will always give us a valid pointer here, even if the face name - // is non-existent. We have to double-check and see if the family name was - // really used. - String winName; - HFONT hfont = createFontIndirectAndGetWinName(family, &winfont, &winName); - if (!hfont) - return 0; - - // 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 - // lfFaceName field of LOGFONT. As a result, we need to check - // if a font has an alternate name. If there is, we need to - // compare it with what's requested in the first place. - String altName; - if (!LookupAltName(family, altName) || - !equalIgnoringCase(altName, winName)) { - DeleteObject(hfont); - return 0; - } - } - - return new FontPlatformData(hfont, - fontDescription.computedPixelSize()); -} - -} diff --git a/webkit/port/platform/graphics/chromium/FontCacheLinux.cpp b/webkit/port/platform/graphics/chromium/FontCacheLinux.cpp deleted file mode 100644 index c8fb0f1..0000000 --- a/webkit/port/platform/graphics/chromium/FontCacheLinux.cpp +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "config.h" -#include "FontCache.h" - -#include <fontconfig/fontconfig.h> - -#include "AtomicString.h" -#include "CString.h" -#include "Font.h" -#include "FontDescription.h" -#include "FontPlatformData.h" -#include "Logging.h" -#include "NotImplemented.h" -#include "SimpleFontData.h" - -#include "SkPaint.h" -#include "SkTypeface.h" -#include "SkUtils.h" - -namespace WebCore { - -void FontCache::platformInit() -{ -} - -const SimpleFontData* FontCache::getFontDataForCharacters(const Font& font, - const UChar* characters, - int length) -{ - FcCharSet* cset = FcCharSetCreate(); - for (int i = 0; i < length; ++i) - FcCharSetAddChar(cset, characters[i]); - - FcPattern* pattern = FcPatternCreate(); - - FcValue fcvalue; - fcvalue.type = FcTypeCharSet; - fcvalue.u.c = cset; - FcPatternAdd(pattern, FC_CHARSET, fcvalue, 0); - - FcConfigSubstitute(0, pattern, FcMatchPattern); - FcDefaultSubstitute(pattern); - - FcResult result; - FcPattern* match = FcFontMatch(0, pattern, &result); - FcPatternDestroy(pattern); - - SimpleFontData* ret = NULL; - - if (match) { - FcChar8* family; - if (FcPatternGetString(match, FC_FAMILY, 0, &family) == FcResultMatch) { - FontPlatformData* fpd = - createFontPlatformData(font.fontDescription(), - AtomicString((char *) family)); - ret = new SimpleFontData(*fpd); - } - FcPatternDestroy(match); - } - - FcCharSetDestroy(cset); - - return ret; -} - -const AtomicString& FontCache::alternateFamilyName(const AtomicString& familyName) -{ - notImplemented(); - - // This is just to stop GCC emitting a warning about returning a reference - // to a temporary variable - static AtomicString a; - return a; -} - -FontPlatformData* FontCache::getSimilarFontPlatformData(const Font& font) -{ - return 0; -} - -FontPlatformData* FontCache::getLastResortFallbackFont(const FontDescription& description) -{ - static AtomicString arialStr("Arial"); - return getCachedFontPlatformData(description, arialStr); -} - -void FontCache::getTraitsInFamily(const AtomicString& familyName, - Vector<unsigned>& traitsMasks) -{ - notImplemented(); -} - -FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, - const AtomicString& family) -{ - const char* name = 0; - CString s; - - if (family.length() == 0) { - static const struct { - FontDescription::GenericFamilyType mType; - const char* mName; - } gNames[] = { - { FontDescription::SerifFamily, "serif" }, - { FontDescription::SansSerifFamily, "sans-serif" }, - { FontDescription::MonospaceFamily, "monospace" }, - { FontDescription::CursiveFamily, "cursive" }, - { FontDescription::FantasyFamily, "fantasy" } - }; - - FontDescription::GenericFamilyType type = fontDescription.genericFamily(); - for (unsigned i = 0; i < SK_ARRAY_COUNT(gNames); i++) { - if (type == gNames[i].mType) { - name = gNames[i].mName; - break; - } - } - // if we fall out of the loop, it's ok for name to still be 0 - } - else { // convert the name to utf8 - s = family.string().utf8(); - name = s.data(); - } - - int style = SkTypeface::kNormal; - if (fontDescription.weight() >= FontWeightBold) - style |= SkTypeface::kBold; - if (fontDescription.italic()) - style |= SkTypeface::kItalic; - - SkTypeface* tf = SkTypeface::Create(name, (SkTypeface::Style)style); - if (!tf) - return NULL; - - FontPlatformData* result = - new FontPlatformData(tf, - fontDescription.computedSize(), - (style & SkTypeface::kBold) && !tf->isBold(), - (style & SkTypeface::kItalic) && !tf->isItalic()); - tf->unref(); - return result; -} - -AtomicString FontCache::getGenericFontForScript(UScriptCode script, - const FontDescription& descript) -{ - notImplemented(); - return AtomicString(); -} - -} // namespace WebCore diff --git a/webkit/port/platform/graphics/chromium/FontChromiumWin.cpp b/webkit/port/platform/graphics/chromium/FontChromiumWin.cpp deleted file mode 100644 index 5f85629..0000000 --- a/webkit/port/platform/graphics/chromium/FontChromiumWin.cpp +++ /dev/null @@ -1,290 +0,0 @@ -/* - * Copyright (C) 2006, 2007 Apple 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: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 <windows.h> - -#include "AffineTransform.h" -#include "ChromiumBridge.h" -#include "Font.h" -#include "FontFallbackList.h" -#include "GlyphBuffer.h" -#include "PlatformContextSkia.h" -#include "SimpleFontData.h" -#include "SkiaFontWin.h" -#include "SkiaUtils.h" -#include "UniscribeHelperTextRun.h" - -#include "skia/ext/platform_canvas_win.h" -#include "skia/ext/skia_utils_win.h" // TODO(brettw) remove this dependency. - -namespace WebCore { - -static bool windowsCanHandleTextDrawing(GraphicsContext* context) -{ - // Check for non-translation transforms. Sometimes zooms will look better in - // Skia, and sometimes better in Windows. The main problem is that zooming - // in using Skia will show you the hinted outlines for the smaller size, - // which look weird. All else being equal, it's better to use Windows' text - // drawing, so we don't check for zooms. - const AffineTransform& xform = context->getCTM(); - if (xform.b() != 0 || // Y skew - xform.c() != 0) // X skew - return false; - - // Check for stroke effects. - if (context->platformContext()->getTextDrawingMode() != cTextFill) - return false; - - // Check for shadow effects. - if (context->platformContext()->getDrawLooper()) - return false; - - return true; -} - -static bool PaintSkiaText(PlatformContextSkia* platformContext, - HFONT hfont, - int numGlyphs, - const WORD* glyphs, - const int* advances, - const SkPoint& origin) -{ - int textMode = platformContext->getTextDrawingMode(); - - // Filling (if necessary). This is the common case. - SkPaint paint; - platformContext->setupPaintForFilling(&paint); - paint.setFlags(SkPaint::kAntiAlias_Flag); - bool didFill = false; - if ((textMode & cTextFill) && SkColorGetA(paint.getColor())) { - if (!SkiaDrawText(hfont, platformContext->canvas(), origin, &paint, - &glyphs[0], &advances[0], numGlyphs)) - return false; - didFill = true; - } - - // Stroking on top (if necessary). - if ((textMode & WebCore::cTextStroke) && - platformContext->getStrokeStyle() != NoStroke && - platformContext->getStrokeThickness() > 0) { - - paint.reset(); - platformContext->setupPaintForStroking(&paint, NULL, 0); - paint.setFlags(SkPaint::kAntiAlias_Flag); - if (didFill) { - // If there is a shadow and we filled above, there will already be - // a shadow. We don't want to draw it again or it will be too dark - // and it will go on top of the fill. - // - // Note that this isn't strictly correct, since the stroke could be - // very thick and the shadow wouldn't account for this. The "right" - // thing would be to draw to a new layer and then draw that layer - // with a shadow. But this is a lot of extra work for something - // that isn't normally an issue. - paint.setLooper(NULL)->safeUnref(); - } - - if (!SkiaDrawText(hfont, platformContext->canvas(), origin, - &paint, &glyphs[0], &advances[0], numGlyphs)) - return false; - } - return true; -} - -void Font::drawGlyphs(GraphicsContext* graphicsContext, - const SimpleFontData* font, - const GlyphBuffer& glyphBuffer, - int from, - int numGlyphs, - const FloatPoint& point) const -{ - PlatformGraphicsContext* context = graphicsContext->platformContext(); - - // Max buffer length passed to the underlying windows API. - const int kMaxBufferLength = 1024; - // Default size for the buffer. It should be enough for most of cases. - const int kDefaultBufferLength = 256; - - SkColor color = context->fillColor(); - unsigned char alpha = SkColorGetA(color); - // Skip 100% transparent text; no need to draw anything. - if (!alpha && context->getStrokeStyle() == NoStroke) - return; - - // Set up our graphics context. - HDC hdc = context->canvas()->beginPlatformPaint(); - HGDIOBJ oldFont = SelectObject(hdc, font->platformData().hfont()); - - // TODO(maruel): http://b/700464 SetTextColor doesn't support transparency. - // Enforce non-transparent color. - color = SkColorSetRGB(SkColorGetR(color), - SkColorGetG(color), - SkColorGetB(color)); - SetTextColor(hdc, skia::SkColorToCOLORREF(color)); - SetBkMode(hdc, TRANSPARENT); - - // Windows needs the characters and the advances in nice contiguous - // buffers, which we build here. - Vector<WORD, kDefaultBufferLength> glyphs; - Vector<int, kDefaultBufferLength> advances; - - // Compute the coordinate. The 'origin' represents the baseline, so we need - // to move it up to the top of the bounding square. - int x = static_cast<int>(point.x()); - int lineTop = static_cast<int>(point.y()) - font->ascent(); - - bool canUseGDI = windowsCanHandleTextDrawing(graphicsContext); - - // We draw the glyphs in chunks to avoid having to do a heap allocation for - // the arrays of characters and advances. Since ExtTextOut is the - // lowest-level text output function on Windows, there should be little - // penalty for splitting up the text. On the other hand, the buffer cannot - // be bigger than 4094 or the function will fail. - int glyphIndex = 0; - while (glyphIndex < numGlyphs) { - // how many chars will be in this chunk? - int curLen = std::min(kMaxBufferLength, numGlyphs - glyphIndex); - - glyphs.resize(curLen); - advances.resize(curLen); - - int curWidth = 0; - for (int i = 0; i < curLen; ++i, ++glyphIndex) { - glyphs[i] = glyphBuffer.glyphAt(from + glyphIndex); - advances[i] = - static_cast<int>(glyphBuffer.advanceAt(from + glyphIndex)); - curWidth += advances[i]; - } - - bool success = false; - for (int executions = 0; executions < 2; ++executions) { - if (canUseGDI) { - success = !!ExtTextOut(hdc, x, lineTop, ETO_GLYPH_INDEX, NULL, - reinterpret_cast<const wchar_t*>(&glyphs[0]), - curLen, &advances[0]); - } else { - // Skia's text draing origin is the baseline, like WebKit, not - // the top, like Windows. - SkPoint origin = { x, point.y() }; - success = PaintSkiaText(context, - font->platformData().hfont(), numGlyphs, - reinterpret_cast<const WORD*>(&glyphs[0]), - &advances[0], origin); - } - - if (!success && executions == 0) { - // Ask the browser to load the font for us and retry. - ChromiumBridge::ensureFontLoaded(font->platformData().hfont()); - continue; - } - break; - } - - ASSERT(success); - - x += curWidth; - } - - SelectObject(hdc, oldFont); - context->canvas()->endPlatformPaint(); -} - -FloatRect Font::selectionRectForComplexText(const TextRun& run, - const IntPoint& point, - int h, - int from, - int to) const -{ - UniscribeHelperTextRun state(run, *this); - float left = static_cast<float>(point.x() + state.CharacterToX(from)); - float right = static_cast<float>(point.x() + state.CharacterToX(to)); - - // If the text is RTL, left will actually be after right. - if (left < right) { - return FloatRect(left, static_cast<float>(point.y()), - right - left, static_cast<float>(h)); - } - return FloatRect(right, static_cast<float>(point.y()), - left - right, static_cast<float>(h)); -} - -void Font::drawComplexText(GraphicsContext* graphicsContext, - const TextRun& run, - const FloatPoint& point, - int from, - int to) const -{ - PlatformGraphicsContext* context = graphicsContext->platformContext(); - UniscribeHelperTextRun state(run, *this); - - SkColor color = context->fillColor(); - unsigned char alpha = SkColorGetA(color); - // Skip 100% transparent text; no need to draw anything. - if (!alpha) - return; - - HDC hdc = context->canvas()->beginPlatformPaint(); - - // TODO(maruel): http://b/700464 SetTextColor doesn't support transparency. - // Enforce non-transparent color. - color = SkColorSetRGB(SkColorGetR(color), - SkColorGetG(color), - SkColorGetB(color)); - SetTextColor(hdc, skia::SkColorToCOLORREF(color)); - SetBkMode(hdc, TRANSPARENT); - - // Uniscribe counts the coordinates from the upper left, while WebKit uses - // the baseline, so we have to subtract off the ascent. - state.Draw(hdc, - static_cast<int>(point.x()), - static_cast<int>(point.y() - ascent()), - from, - to); - context->canvas()->endPlatformPaint(); -} - -float Font::floatWidthForComplexText(const TextRun& run) const -{ - UniscribeHelperTextRun state(run, *this); - return static_cast<float>(state.Width()); -} - -int Font::offsetForPositionForComplexText(const TextRun& run, int x, - bool includePartialGlyphs) const -{ - // Mac code ignores includePartialGlyphs, and they don't know what it's - // supposed to do, so we just ignore it as well. - UniscribeHelperTextRun state(run, *this); - int char_index = state.XToCharacter(x); - - // XToCharacter will return -1 if the position is before the first - // character (we get called like this sometimes). - if (char_index < 0) - char_index = 0; - return char_index; -} - -} // namespace WebCore diff --git a/webkit/port/platform/graphics/chromium/FontCustomPlatformData.cpp b/webkit/port/platform/graphics/chromium/FontCustomPlatformData.cpp deleted file mode 100644 index 9105a8c..0000000 --- a/webkit/port/platform/graphics/chromium/FontCustomPlatformData.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2007 Apple Computer, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#include "config.h" -#include "FontCustomPlatformData.h" - -#include "SharedBuffer.h" -#include "FontPlatformData.h" -#include "NotImplemented.h" - -namespace WebCore { - -FontCustomPlatformData::~FontCustomPlatformData() -{ - // FIXME: Release the HFONT ref? -} - -FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, bool italic) -{ - return FontPlatformData(m_font, size); -} - -FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer) -{ - ASSERT_ARG(buffer, buffer); - -#if PLATFORM(WIN_OS) - HFONT font = 0; - // FIXME: Figure out some way to get Windows to give us back a font object. - if (!font) - return 0; - return new FontCustomPlatformData(font); -#else - notImplemented(); -#endif -} - -} diff --git a/webkit/port/platform/graphics/chromium/FontCustomPlatformData.h b/webkit/port/platform/graphics/chromium/FontCustomPlatformData.h deleted file mode 100644 index 8aa0fea..0000000 --- a/webkit/port/platform/graphics/chromium/FontCustomPlatformData.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2007 Apple Computer, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#ifndef FontCustomPlatformData_h -#define FontCustomPlatformData_h - -#if PLATFORM(DARWIN) -// TODO(port): This #include isn't strictly kosher, but we're currently using -// the Mac font code from upstream WebKit, and we need to pick up their header. -#undef FontCustomPlatformData_h -#include "third_party/WebKit/WebCore/platform/graphics/mac/FontCustomPlatformData.h" -#else - -#include <wtf/Noncopyable.h> - -#if PLATFORM(WIN_OS) -#include <windows.h> -#endif - -namespace WebCore { - -class FontPlatformData; -class SharedBuffer; - -struct FontCustomPlatformData : Noncopyable { -#if PLATFORM(WIN_OS) - FontCustomPlatformData(HFONT font) - : m_font(font) - {} -#endif - - ~FontCustomPlatformData(); - - FontPlatformData fontPlatformData(int size, bool bold, bool italic); - -#if PLATFORM(WIN_OS) - HFONT m_font; -#endif -}; - -FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer*); - -} - -#endif -#endif diff --git a/webkit/port/platform/graphics/chromium/FontLinux.cpp b/webkit/port/platform/graphics/chromium/FontLinux.cpp deleted file mode 100644 index 7e2ebac..0000000 --- a/webkit/port/platform/graphics/chromium/FontLinux.cpp +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "config.h" -#include "Font.h" - -#include "FloatRect.h" -#include "GlyphBuffer.h" -#include "GraphicsContext.h" -#include "NotImplemented.h" -#include "PlatformContextSkia.h" -#include "SimpleFontData.h" - -#include "SkCanvas.h" -#include "SkPaint.h" -#include "SkTemplates.h" -#include "SkTypeface.h" -#include "SkUtils.h" - -namespace WebCore { - -void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font, - const GlyphBuffer& glyphBuffer, int from, int numGlyphs, - const FloatPoint& point) const { - SkCanvas* canvas = gc->platformContext()->canvas(); - SkPaint paint; - - font->platformData().setupPaint(&paint); - paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); - paint.setColor(gc->fillColor().rgb()); - - SkASSERT(sizeof(GlyphBufferGlyph) == sizeof(uint16_t)); // compile-time assert - - const GlyphBufferGlyph* glyphs = glyphBuffer.glyphs(from); - SkScalar x = SkFloatToScalar(point.x()); - SkScalar y = SkFloatToScalar(point.y()); - - // TODO(port): text rendering speed: - // Android has code in their WebCore fork to special case when the - // GlyphBuffer has no advances other than the defaults. In that case the - // text drawing can proceed faster. However, it's unclear when those - // patches may be upstreamed to WebKit so we always use the slower path - // here. - const GlyphBufferAdvance* adv = glyphBuffer.advances(from); - SkAutoSTMalloc<32, SkPoint> storage(numGlyphs); - SkPoint* pos = storage.get(); - - for (int i = 0; i < numGlyphs; i++) { - pos[i].set(x, y); - x += SkFloatToScalar(adv[i].width()); - y += SkFloatToScalar(adv[i].height()); - } - canvas->drawPosText(glyphs, numGlyphs << 1, pos, paint); -} - -void Font::drawComplexText(GraphicsContext* context, const TextRun& run, - const FloatPoint& point, int from, int to) const -{ - notImplemented(); -} - -float Font::floatWidthForComplexText(const TextRun& run) const -{ - notImplemented(); - return 0; -} - -int Font::offsetForPositionForComplexText(const TextRun& run, int x, - bool includePartialGlyphs) const -{ - notImplemented(); - return 0; -} - -FloatRect Font::selectionRectForComplexText(const TextRun& run, - const IntPoint& point, int h, - int from, int to) const -{ - notImplemented(); - return FloatRect(); -} - -} // namespace WebCore diff --git a/webkit/port/platform/graphics/chromium/FontPlatformData.h b/webkit/port/platform/graphics/chromium/FontPlatformData.h deleted file mode 100644 index ea3dba5..0000000 --- a/webkit/port/platform/graphics/chromium/FontPlatformData.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef FontPlatformData_h -#define FontPlatformData_h - -#include "config.h" -#include "build/build_config.h" - -#if defined(OS_WIN) -#include "FontPlatformDataChromiumWin.h" -#elif defined(OS_LINUX) -#include "FontPlatformDataLinux.h" -#elif defined(OS_MACOSX) -// TODO(port): This #include isn't strictly kosher, but we're currently using -// the Mac font code from upstream WebKit, and we need to pick up their header. -#undef FontPlatformData_h -#include "third_party/WebKit/WebCore/platform/graphics/mac/FontPlatformData.h" -#endif - -#endif // ifndef FontPlatformData_h diff --git a/webkit/port/platform/graphics/chromium/FontPlatformDataChromiumWin.cpp b/webkit/port/platform/graphics/chromium/FontPlatformDataChromiumWin.cpp deleted file mode 100644 index 3a11c1c..0000000 --- a/webkit/port/platform/graphics/chromium/FontPlatformDataChromiumWin.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - * This file is part of the internal font implementation. It should not be included by anyone other than - * FontMac.cpp, FontWin.cpp and Font.cpp. - * - * Copyright (C) 2006, 2007 Apple Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" -#include "FontPlatformData.h" - -#include <windows.h> -#include <objidl.h> -#include <mlang.h> - -#include "ChromiumBridge.h" -#include "SkiaFontWin.h" - -namespace WebCore { - -FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType) - : m_font(hashTableDeletedFontValue()) - , m_size(-1) - , m_scriptCache(0) - , m_scriptFontProperties(0) -{ -} - -FontPlatformData::FontPlatformData() - : m_font(0) - , m_size(0) - , m_scriptCache(0) - , m_scriptFontProperties(0) -{ -} - -FontPlatformData::FontPlatformData(HFONT font, float size) - : m_font(RefCountedHFONT::create(font)) - , m_size(size) - , m_scriptCache(0) - , m_scriptFontProperties(0) -{ -} - -// TODO(jhaas): this ctor is needed for SVG fonts but doesn't seem -// to do much -FontPlatformData::FontPlatformData(float size, bool bold, bool oblique) - : m_font(0) - , m_size(size) - , m_scriptCache(0) - , m_scriptFontProperties(0) -{ -} - -FontPlatformData::FontPlatformData(const FontPlatformData& data) - : m_font(data.m_font) - , m_size(data.m_size) - , m_scriptCache(0) - , m_scriptFontProperties(0) -{ -} - -FontPlatformData& FontPlatformData::operator=(const FontPlatformData& data) -{ - if (this != &data) { - m_font = data.m_font; - m_size = data.m_size; - - // The following fields will get re-computed if necessary. - - ScriptFreeCache(&m_scriptCache); - m_scriptCache = 0; - - delete m_scriptFontProperties; - m_scriptFontProperties = 0; - } - return *this; -} - -FontPlatformData::~FontPlatformData() -{ - ScriptFreeCache(&m_scriptCache); - m_scriptCache = 0; - - delete m_scriptFontProperties; - m_scriptFontProperties = 0; -} - -FontPlatformData::RefCountedHFONT::~RefCountedHFONT() -{ - if (m_hfont != reinterpret_cast<HFONT>(-1)) { - RemoveFontFromSkiaFontWinCache(m_hfont); - DeleteObject(m_hfont); - } -} - -FontPlatformData::RefCountedHFONT* FontPlatformData::hashTableDeletedFontValue() -{ - static RefPtr<RefCountedHFONT> deletedValue = - RefCountedHFONT::create(reinterpret_cast<HFONT>(-1)); - return deletedValue.get(); -} - -SCRIPT_FONTPROPERTIES* FontPlatformData::scriptFontProperties() const -{ - if (!m_scriptFontProperties) { - m_scriptFontProperties = new SCRIPT_FONTPROPERTIES; - memset(m_scriptFontProperties, 0, sizeof(SCRIPT_FONTPROPERTIES)); - m_scriptFontProperties->cBytes = sizeof(SCRIPT_FONTPROPERTIES); - HRESULT result = ScriptGetFontProperties(0, scriptCache(), - m_scriptFontProperties); - if (result == E_PENDING) { - HDC dc = GetDC(0); - HGDIOBJ oldFont = SelectObject(dc, hfont()); - HRESULT hr = ScriptGetFontProperties(dc, scriptCache(), - m_scriptFontProperties); - if (S_OK != hr) { - if (ChromiumBridge::ensureFontLoaded(hfont())) { - // Retry ScriptGetFontProperties. - // TODO(nsylvain): Handle gracefully the error if this call - // also fails. See bug 1136944. - hr = ScriptGetFontProperties(dc, scriptCache(), - m_scriptFontProperties); - if (S_OK != hr) { - ASSERT_NOT_REACHED(); - } - } - } - - SelectObject(dc, oldFont); - ReleaseDC(0, dc); - } - } - return m_scriptFontProperties; -} - -} diff --git a/webkit/port/platform/graphics/chromium/FontPlatformDataChromiumWin.h b/webkit/port/platform/graphics/chromium/FontPlatformDataChromiumWin.h deleted file mode 100644 index 80f9df3..0000000 --- a/webkit/port/platform/graphics/chromium/FontPlatformDataChromiumWin.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - * This file is part of the internal font implementation. It should not be included by anyone other than - * FontMac.cpp, FontWin.cpp and Font.cpp. - * - * Copyright (C) 2006, 2007 Apple Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - */ - -#ifndef FontPlatformDataWin_H -#define FontPlatformDataWin_H - -#include "config.h" - -#include "StringImpl.h" -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -// TODO(tc): Once this file is only included by the ChromiumWin build, we can -// remove the PLATFORM #ifs. -#if PLATFORM(WIN_OS) -#include <usp10.h> -#endif - -typedef struct HFONT__ *HFONT; - -namespace WebCore { - -class FontDescription; - -class FontPlatformData -{ -public: - // Used for deleted values in the font cache's hash tables. The hash table - // will create us with this structure, and it will compare other values - // to this "Deleted" one. It expects the Deleted one to be differentiable - // from the NULL one (created with the empty constructor), so we can't just - // set everything to NULL. - FontPlatformData(WTF::HashTableDeletedValueType); - FontPlatformData(); - FontPlatformData(HFONT hfont, float size); - FontPlatformData(float size, bool bold, bool oblique); - FontPlatformData(const FontPlatformData& data); - - FontPlatformData& operator=(const FontPlatformData& data); - - bool isHashTableDeletedValue() const { return m_font == hashTableDeletedFontValue(); } - - ~FontPlatformData(); - - HFONT hfont() const { return m_font ? m_font->hfont() : 0; } - float size() const { return m_size; } - - unsigned hash() const - { - return m_font ? m_font->hash() : NULL; - } - - bool operator==(const FontPlatformData& other) const - { - return m_font == other.m_font && m_size == other.m_size; - } - -#if PLATFORM(WIN_OS) - SCRIPT_FONTPROPERTIES* scriptFontProperties() const; - SCRIPT_CACHE* scriptCache() const { return &m_scriptCache; } -#endif - -private: - // We refcount the internal HFONT so that FontPlatformData can be - // efficiently copied. WebKit depends on being able to copy it, and we - // don't really want to re-create the HFONT. - class RefCountedHFONT : public RefCounted<RefCountedHFONT> { - public: - static PassRefPtr<RefCountedHFONT> create(HFONT hfont) - { - return adoptRef(new RefCountedHFONT(hfont)); - } - - ~RefCountedHFONT(); - - HFONT hfont() const { return m_hfont; } - unsigned hash() const - { - return StringImpl::computeHash(reinterpret_cast<const UChar*>(&m_hfont), sizeof(HFONT) / sizeof(UChar)); - } - - bool operator==(const RefCountedHFONT& other) const - { - return m_hfont == other.m_hfont; - } - - private: - // The create() function assumes there is already a refcount of one - // so it can do adoptRef. - RefCountedHFONT(HFONT hfont) : m_hfont(hfont) - { - } - - HFONT m_hfont; - }; - - static RefCountedHFONT* hashTableDeletedFontValue(); - - RefPtr<RefCountedHFONT> m_font; - float m_size; // Point size of the font in pixels. - -#if PLATFORM(WIN_OS) - mutable SCRIPT_CACHE m_scriptCache; - mutable SCRIPT_FONTPROPERTIES* m_scriptFontProperties; -#endif -}; - -} - -#endif diff --git a/webkit/port/platform/graphics/chromium/FontPlatformDataLinux.cpp b/webkit/port/platform/graphics/chromium/FontPlatformDataLinux.cpp deleted file mode 100644 index 01167da..0000000 --- a/webkit/port/platform/graphics/chromium/FontPlatformDataLinux.cpp +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "config.h" -#include "FontPlatformData.h" - -#include "SkPaint.h" -#include "SkTypeface.h" - -namespace WebCore { - -FontPlatformData::FontPlatformData(const FontPlatformData& src) -{ - src.m_typeface->safeRef(); - m_typeface = src.m_typeface; - - m_textSize = src.m_textSize; - m_fakeBold = src.m_fakeBold; - m_fakeItalic = src.m_fakeItalic; -} - -FontPlatformData::FontPlatformData(SkTypeface* tf, float textSize, bool fakeBold, bool fakeItalic) - : m_typeface(tf) - , m_textSize(textSize) - , m_fakeBold(fakeBold) - , m_fakeItalic(fakeItalic) -{ - m_typeface->safeRef(); -} - -FontPlatformData::FontPlatformData(const FontPlatformData& src, float textSize) - : m_typeface(src.m_typeface) - , m_textSize(textSize) - , m_fakeBold(src.m_fakeBold) - , m_fakeItalic(src.m_fakeItalic) -{ - m_typeface->safeRef(); -} - -FontPlatformData::~FontPlatformData() -{ - m_typeface->safeUnref(); -} - -FontPlatformData& FontPlatformData::operator=(const FontPlatformData& src) -{ - SkRefCnt_SafeAssign(m_typeface, src.m_typeface); - - m_textSize = src.m_textSize; - m_fakeBold = src.m_fakeBold; - m_fakeItalic = src.m_fakeItalic; - - return *this; -} - -void FontPlatformData::setupPaint(SkPaint* paint) const -{ - const float ts = m_textSize > 0 ? m_textSize : 12; - - paint->setAntiAlias(false); - paint->setSubpixelText(false); - paint->setTextSize(SkFloatToScalar(ts)); - paint->setTypeface(m_typeface); - paint->setFakeBoldText(m_fakeBold); - paint->setTextSkewX(m_fakeItalic ? -SK_Scalar1/4 : 0); - paint->setTextEncoding(SkPaint::kUTF16_TextEncoding); -} - -bool FontPlatformData::operator==(const FontPlatformData& a) const -{ - // If either of the typeface pointers are invalid (either NULL or the - // special deleted value) then we test for pointer equality. Otherwise, we - // call SkTypeface::Equal on the valid pointers. - const bool typefaces_equal = - (m_typeface == hashTableDeletedFontValue() || - a.m_typeface == hashTableDeletedFontValue() || - !m_typeface || !a.m_typeface) ? - (m_typeface == a.m_typeface) : - SkTypeface::Equal(m_typeface, a.m_typeface); - return typefaces_equal && - m_textSize == a.m_textSize && - m_fakeBold == a.m_fakeBold && - m_fakeItalic == a.m_fakeItalic; -} - -unsigned FontPlatformData::hash() const -{ - // This hash is taken from Android code. It is not our fault. - unsigned h = SkTypeface::UniqueID(m_typeface); - h ^= 0x01010101 * (((int)m_fakeBold << 1) | (int)m_fakeItalic); - - // This memcpy is to avoid a reinterpret_cast that breaks strict-aliasing - // rules. Memcpy is generally optimized enough so that performance doesn't - // matter here. - uint32_t textsize_bytes; - memcpy(&textsize_bytes, &m_textSize, sizeof(uint32_t)); - h ^= textsize_bytes; - - return h; -} - -bool FontPlatformData::isFixedPitch() const -{ - notImplemented(); - return false; -} - -} // namespace WebCore diff --git a/webkit/port/platform/graphics/chromium/FontPlatformDataLinux.h b/webkit/port/platform/graphics/chromium/FontPlatformDataLinux.h deleted file mode 100644 index 0d67b24..0000000 --- a/webkit/port/platform/graphics/chromium/FontPlatformDataLinux.h +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef FontPlatformDataLinux_h -#define FontPlatformDataLinux_h - -#include "config.h" -#include "build/build_config.h" - -#include "StringImpl.h" -#include "NotImplemented.h" -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -class SkPaint; -class SkTypeface; - -namespace WebCore { - -class FontDescription; - -// ----------------------------------------------------------------------------- -// FontPlatformData is the handle which WebKit has on a specific face. A face -// is the tuple of (font, size, ...etc). Here we are just wrapping a Skia -// SkTypeface pointer and dealing with the reference counting etc. -// ----------------------------------------------------------------------------- -class FontPlatformData { -public: - // Used for deleted values in the font cache's hash tables. The hash table - // will create us with this structure, and it will compare other values - // to this "Deleted" one. It expects the Deleted one to be differentiable - // from the NULL one (created with the empty constructor), so we can't just - // set everything to NULL. - FontPlatformData(WTF::HashTableDeletedValueType) - : m_typeface(hashTableDeletedFontValue()) - , m_textSize(0) - , m_fakeBold(false) - , m_fakeItalic(false) - { } - - FontPlatformData() - : m_typeface(0) - , m_textSize(0) - , m_fakeBold(false) - , m_fakeItalic(false) - { } - - FontPlatformData(float textSize, bool fakeBold, bool fakeItalic) - : m_typeface(0) - , m_textSize(textSize) - , m_fakeBold(fakeBold) - , m_fakeItalic(fakeItalic) - { } - - FontPlatformData(const FontPlatformData&); - FontPlatformData(SkTypeface *, float textSize, bool fakeBold, bool fakeItalic); - FontPlatformData(const FontPlatformData& src, float textSize); - ~FontPlatformData(); - - // ------------------------------------------------------------------------- - // Return true iff this font is monospaced (i.e. every glyph has an equal x - // advance) - // ------------------------------------------------------------------------- - bool isFixedPitch() const; - - // ------------------------------------------------------------------------- - // Setup a Skia painting context to use this font. - // ------------------------------------------------------------------------- - void setupPaint(SkPaint*) const; - - unsigned hash() const; - float size() const { return m_textSize; } - - bool operator==(const FontPlatformData& other) const; - FontPlatformData& operator=(const FontPlatformData& src); - bool isHashTableDeletedValue() const { return m_typeface == hashTableDeletedFontValue(); } - -private: - SkTypeface* m_typeface; - float m_textSize; - bool m_fakeBold; - bool m_fakeItalic; - - SkTypeface* hashTableDeletedFontValue() const { return reinterpret_cast<SkTypeface*>(-1); } -}; - -} // namespace WebCore - -#endif // ifdef FontPlatformData_h diff --git a/webkit/port/platform/graphics/chromium/FontUtilsChromiumWin.cpp b/webkit/port/platform/graphics/chromium/FontUtilsChromiumWin.cpp deleted file mode 100644 index 3128259..0000000 --- a/webkit/port/platform/graphics/chromium/FontUtilsChromiumWin.cpp +++ /dev/null @@ -1,338 +0,0 @@ -// Copyright (c) 2006-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 "FontUtilsChromiumWin.h" - -#include <limits> - -#include "PlatformString.h" -#include "StringHash.h" -#include "UniscribeHelper.h" -#include <unicode/locid.h> -#include <unicode/uchar.h> -#include <wtf/HashMap.h> - -namespace WebCore { - -namespace { - -// A simple mapping from UScriptCode to family name. This is a sparse array, -// which works well since the range of UScriptCode values is small. -typedef const UChar* ScriptToFontMap[USCRIPT_CODE_LIMIT]; - -void initializeScriptFontMap(ScriptToFontMap& scriptFontMap) -{ - struct FontMap { - UScriptCode script; - const UChar* family; - }; - - const static FontMap fontMap[] = { - {USCRIPT_LATIN, L"times new roman"}, - {USCRIPT_GREEK, L"times new roman"}, - {USCRIPT_CYRILLIC, L"times new roman"}, - {USCRIPT_SIMPLIFIED_HAN, L"simsun"}, - //{USCRIPT_TRADITIONAL_HAN, L"pmingliu"}, - {USCRIPT_HIRAGANA, L"ms pgothic"}, - {USCRIPT_KATAKANA, L"ms pgothic"}, - {USCRIPT_KATAKANA_OR_HIRAGANA, L"ms pgothic"}, - {USCRIPT_HANGUL, L"gulim"}, - {USCRIPT_THAI, L"tahoma"}, - {USCRIPT_HEBREW, L"david"}, - {USCRIPT_ARABIC, L"tahoma"}, - {USCRIPT_DEVANAGARI, L"mangal"}, - {USCRIPT_BENGALI, L"vrinda"}, - {USCRIPT_GURMUKHI, L"raavi"}, - {USCRIPT_GUJARATI, L"shruti"}, - {USCRIPT_ORIYA, L"kalinga"}, - {USCRIPT_TAMIL, L"latha"}, - {USCRIPT_TELUGU, L"gautami"}, - {USCRIPT_KANNADA, L"tunga"}, - {USCRIPT_MALAYALAM, L"kartika"}, - {USCRIPT_LAO, L"dokchampa"}, - {USCRIPT_TIBETAN, L"microsoft himalaya"}, - {USCRIPT_GEORGIAN, L"sylfaen"}, - {USCRIPT_ARMENIAN, L"sylfaen"}, - {USCRIPT_ETHIOPIC, L"nyala"}, - {USCRIPT_CANADIAN_ABORIGINAL, L"euphemia"}, - {USCRIPT_CHEROKEE, L"plantagenet cherokee"}, - {USCRIPT_YI, L"microsoft yi balti"}, - {USCRIPT_SINHALA, L"iskoola pota"}, - {USCRIPT_SYRIAC, L"estrangelo edessa"}, - {USCRIPT_KHMER, L"daunpenh"}, - {USCRIPT_THAANA, L"mv boli"}, - {USCRIPT_MONGOLIAN, L"mongolian balti"}, - {USCRIPT_MYANMAR, L"padauk"}, - // For USCRIPT_COMMON, we map blocks to scripts when - // that makes sense. - }; - - for (int i = 0; i < sizeof(fontMap) / sizeof(fontMap[0]); ++i) - scriptFontMap[fontMap[i].script] = fontMap[i].family; - - // Initialize the locale-dependent mapping. - // Since Chrome synchronizes the ICU default locale with its UI locale, - // this ICU locale tells the current UI locale of Chrome. - Locale locale = Locale::getDefault(); - const UChar* localeFamily = NULL; - if (locale == Locale::getJapanese()) { - localeFamily = scriptFontMap[USCRIPT_HIRAGANA]; - } else if (locale == Locale::getKorean()) { - localeFamily = scriptFontMap[USCRIPT_HANGUL]; - } else { - // Use Simplified Chinese font for all other locales including - // Traditional Chinese because Simsun (SC font) has a wider - // coverage (covering both SC and TC) than PMingLiu (TC font). - // This also speeds up the TC version of Chrome when rendering SC - // pages. - localeFamily = scriptFontMap[USCRIPT_SIMPLIFIED_HAN]; - } - if (localeFamily) - scriptFontMap[USCRIPT_HAN] = localeFamily; -} - -const int kUndefinedAscent = std::numeric_limits<int>::min(); - -// Given an HFONT, return the ascent. If GetTextMetrics fails, -// kUndefinedAscent is returned, instead. -int getAscent(HFONT hfont) -{ - HDC dc = GetDC(NULL); - HGDIOBJ oldFont = SelectObject(dc, hfont); - TEXTMETRIC tm; - BOOL gotMetrics = GetTextMetrics(dc, &tm); - SelectObject(dc, oldFont); - ReleaseDC(NULL, dc); - return gotMetrics ? tm.tmAscent : kUndefinedAscent; -} - -struct FontData { - FontData() : hfont(NULL), ascent(kUndefinedAscent), scriptCache(NULL) {} - HFONT hfont; - int ascent; - mutable SCRIPT_CACHE scriptCache; -}; - -// Again, using hash_map does not earn us much here. page_cycler_test intl2 -// gave us a 'better' result with map than with hash_map even though they're -// well-within 1-sigma of each other so that the difference is not significant. -// On the other hand, some pages in intl2 seem to take longer to load with map -// in the 1st pass. Need to experiment further. -typedef HashMap<String, FontData> FontDataCache; - -} // namespace - -// TODO(jungshik) : this is font fallback code version 0.1 -// - Cover all the scripts -// - Get the default font for each script/generic family from the -// preference instead of hardcoding in the source. -// (at least, read values from the registry for IE font settings). -// - Support generic families (from FontDescription) -// - If the default font for a script is not available, -// try some more fonts known to support it. Finally, we can -// use EnumFontFamilies or similar APIs to come up with a list of -// fonts supporting the script and cache the result. -// - Consider using UnicodeSet (or UnicodeMap) converted from -// GLYPHSET (BMP) or directly read from truetype cmap tables to -// keep track of which character is supported by which font -// - Update script_font_cache in response to WM_FONTCHANGE - -const UChar* getFontFamilyForScript(UScriptCode script, - FontDescription::GenericFamilyType generic) -{ - static ScriptToFontMap scriptFontMap; - static bool initialized = false; - if (!initialized) { - initializeScriptFontMap(scriptFontMap); - initialized = true; - } - if (script == USCRIPT_INVALID_CODE) - return NULL; - ASSERT(script < USCRIPT_CODE_LIMIT); - return scriptFontMap[script]; -} - -// TODO(jungshik) -// - Handle 'Inherited', 'Common' and 'Unknown' -// (see http://www.unicode.org/reports/tr24/#Usage_Model ) -// For 'Inherited' and 'Common', perhaps we need to -// accept another parameter indicating the previous family -// and just return it. -// - All the characters (or characters up to the point a single -// font can cover) need to be taken into account -const UChar* getFallbackFamily(const UChar *characters, - int length, - FontDescription::GenericFamilyType generic, - UChar32 *charChecked, - UScriptCode *scriptChecked) -{ - ASSERT(characters && characters[0] && length > 0); - UScriptCode script = USCRIPT_COMMON; - - // Sometimes characters common to script (e.g. space) is at - // the beginning of a string so that we need to skip them - // to get a font required to render the string. - int i = 0; - UChar32 ucs4 = 0; - while (i < length && script == USCRIPT_COMMON || - script == USCRIPT_INVALID_CODE) { - U16_NEXT(characters, i, length, ucs4); - UErrorCode err = U_ZERO_ERROR; - script = uscript_getScript(ucs4, &err); - // silently ignore the error - } - - // hack for full width ASCII. For the full-width ASCII, use the font - // for Han (which is locale-dependent). - if (0xFF00 < ucs4 && ucs4 < 0xFF5F) - script = USCRIPT_HAN; - - // There are a lot of characters in USCRIPT_COMMON that can be covered - // by fonts for scripts closely related to them. See - // http://unicode.org/cldr/utility/list-unicodeset.jsp?a=[:Script=Common:] - // TODO(jungshik): make this more efficient with a wider coverage - if (script == USCRIPT_COMMON || script == USCRIPT_INHERITED) { - UBlockCode block = ublock_getCode(ucs4); - switch (block) { - case UBLOCK_BASIC_LATIN: - script = USCRIPT_LATIN; - break; - case UBLOCK_CJK_SYMBOLS_AND_PUNCTUATION: - script = USCRIPT_HAN; - break; - case UBLOCK_HIRAGANA: - case UBLOCK_KATAKANA: - script = USCRIPT_HIRAGANA; - break; - case UBLOCK_ARABIC: - script = USCRIPT_ARABIC; - break; - case UBLOCK_GREEK: - script = USCRIPT_GREEK; - break; - case UBLOCK_DEVANAGARI: - // For Danda and Double Danda (U+0964, U+0965), use a Devanagari - // font for now although they're used by other scripts as well. - // Without a context, we can't do any better. - script = USCRIPT_DEVANAGARI; - break; - case UBLOCK_ARMENIAN: - script = USCRIPT_ARMENIAN; - break; - case UBLOCK_GEORGIAN: - script = USCRIPT_GEORGIAN; - break; - case UBLOCK_KANNADA: - script = USCRIPT_KANNADA; - break; - } - } - - // Another lame work-around to cover non-BMP characters. - const UChar* family = getFontFamilyForScript(script, generic); - if (!family) { - int plane = ucs4 >> 16; - switch (plane) { - case 1: - family = L"code2001"; - break; - case 2: - family = L"simsun-extb"; - break; - default: - family = L"lucida sans unicode"; - } - } - - if (charChecked) - *charChecked = ucs4; - if (scriptChecked) - *scriptChecked = script; - return family; -} - -// Be aware that this is not thread-safe. -bool getDerivedFontData(const UChar *family, - int style, - LOGFONT *logfont, - int *ascent, - HFONT *hfont, - SCRIPT_CACHE **scriptCache) { - ASSERT(logfont && family && *family); - - // It does not matter that we leak font data when we exit. - static FontDataCache fontDataCache; - - // TODO(jungshik) : This comes up pretty high in the profile so that - // we need to measure whether using SHA256 (after coercing all the - // fields to char*) is faster than String::format. - String fontKey = String::format("%1d:%d:%ls", style, logfont->lfHeight, family); - FontDataCache::iterator iter = fontDataCache.find(fontKey); - FontData *derived; - if (iter == fontDataCache.end()) { - ASSERT(wcslen(family) < LF_FACESIZE); - wcscpy_s(logfont->lfFaceName, LF_FACESIZE, family); - // TODO(jungshik): CreateFontIndirect always comes up with - // a font even if there's no font matching the name. Need to - // check it against what we actually want (as is done in - // FontCacheWin.cpp) - pair<FontDataCache::iterator, bool> entry = fontDataCache.add(fontKey, FontData()); - derived = &entry.first->second; - derived->hfont = CreateFontIndirect(logfont); - // GetAscent may return kUndefinedAscent, but we still want to - // cache it so that we won't have to call CreateFontIndirect once - // more for HFONT next time. - derived->ascent = getAscent(derived->hfont); - } else { - derived = &iter->second; - // Last time, GetAscent failed so that only HFONT was - // cached. Try once more assuming that TryPreloadFont - // was called by a caller between calls. - if (kUndefinedAscent == derived->ascent) - derived->ascent = getAscent(derived->hfont); - } - *hfont = derived->hfont; - *ascent = derived->ascent; - *scriptCache = &(derived->scriptCache); - return *ascent != kUndefinedAscent; -} - -int getStyleFromLogfont(const LOGFONT* logfont) { - // TODO(jungshik) : consider defining UNDEFINED or INVALID for style and - // returning it when logfont is NULL - if (!logfont) { - ASSERT_NOT_REACHED(); - return FontStyleNormal; - } - return (logfont->lfItalic ? FontStyleItalic : FontStyleNormal) | - (logfont->lfUnderline ? FontStyleUnderlined : FontStyleNormal) | - (logfont->lfWeight >= 700 ? FontStyleBold : FontStyleNormal); -} - -} // namespace WebCore diff --git a/webkit/port/platform/graphics/chromium/FontUtilsChromiumWin.h b/webkit/port/platform/graphics/chromium/FontUtilsChromiumWin.h deleted file mode 100644 index 82162f4..0000000 --- a/webkit/port/platform/graphics/chromium/FontUtilsChromiumWin.h +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (c) 2006-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. - -// A collection of utilities for font handling. - -#ifndef FontUtilsWin_h -#define FontUtilsWin_h - -#include <usp10.h> -#include <wchar.h> -#include <windows.h> - -#include "FontDescription.h" -#include <unicode/uscript.h> - -namespace WebCore { - -// Return a font family that supports a script and belongs to |generic| font -// family. It can return NULL and a caller has to implement its own fallback. -const UChar* getFontFamilyForScript(UScriptCode script, - FontDescription::GenericFamilyType generic); - -// Return a font family that can render |characters| based on -// what script characters belong to. When char_checked is non-NULL, -// it's filled with the character used to determine the script. -// When script_checked is non-NULL, the script used to determine -// the family is returned. -// TODO(jungshik) : This function needs a total overhaul. -const UChar* getFallbackFamily(const UChar* characters, - int length, - FontDescription::GenericFamilyType generic, - UChar32 *charChecked, - UScriptCode *scriptChecked); - -// Derive a new HFONT by replacing lfFaceName of LOGFONT with |family|, -// calculate the ascent for the derived HFONT, and initialize SCRIPT_CACHE -// in FontData. -// |style| is only used for cache key generation. |style| is -// bit-wise OR of BOLD(1), UNDERLINED(2) and ITALIC(4) and -// should match what's contained in LOGFONT. It should be calculated -// by calling GetStyleFromLogFont. -// Returns false if the font is not accessible, in which case |ascent| field -// of |fontdata| is set to kUndefinedAscent. -// Be aware that this is not thread-safe. -// TODO(jungshik): Instead of having three out params, we'd better have one -// (|*FontData|), but somehow it mysteriously messes up the layout for -// certain complex script pages (e.g. hi.wikipedia.org) and also crashes -// at the start-up if recently visited page list includes pages with complex -// scripts in their title. Moreover, somehow the very first-pass of -// intl2 page-cycler test is noticeably slower with one out param than -// the current version although the subsequent 9 passes take about the -// same time. -bool getDerivedFontData(const UChar *family, - int style, - LOGFONT *logfont, - int *ascent, - HFONT *hfont, - SCRIPT_CACHE **scriptCache); - -enum { - FontStyleNormal = 0, - FontStyleBold = 1, - FontStyleItalic = 2, - FontStyleUnderlined = 4 -}; - -// Derive style (bit-wise OR of FONT_STYLE_BOLD, FONT_STYLE_UNDERLINED, and -// FONT_STYLE_ITALIC) from LOGFONT. Returns 0 if |*logfont| is NULL. -int getStyleFromLogfont(const LOGFONT *logfont); - -} // namespace WebCore - -#endif // FontUtilsWin_h diff --git a/webkit/port/platform/graphics/chromium/GlyphPageTreeNodeChromiumWin.cpp b/webkit/port/platform/graphics/chromium/GlyphPageTreeNodeChromiumWin.cpp deleted file mode 100644 index 1f29c88..0000000 --- a/webkit/port/platform/graphics/chromium/GlyphPageTreeNodeChromiumWin.cpp +++ /dev/null @@ -1,242 +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 <windows.h> -#include <vector> - -#include "ChromiumBridge.h" -#include "ChromiumUtilsWin.h" -#include "Font.h" -#include "GlyphPageTreeNode.h" -#include "SimpleFontData.h" -#include "UniscribeHelperTextRun.h" - -namespace WebCore -{ - -// Fills one page of font data pointers with NULL to indicate that there -// are no glyphs for the characters. -static void fillEmptyGlyphs(GlyphPage* page) -{ - for (int i = 0; i < GlyphPage::size; ++i) - page->setGlyphDataForIndex(i, NULL, NULL); -} - -// Lazily initializes space glyph -static Glyph initSpaceGlyph(HDC dc, Glyph* space_glyph) -{ - if (*space_glyph) - return *space_glyph; - static wchar_t space = ' '; - GetGlyphIndices(dc, &space, 1, space_glyph, 0); - return *space_glyph; -} - -// Fills a page of glyphs in the Basic Multilingual Plane (<= U+FFFF). We -// can use the standard Windows GDI functions here. The input buffer size is -// assumed to be GlyphPage::size. Returns true if any glyphs were found. -static bool fillBMPGlyphs(UChar* buffer, - GlyphPage* page, - const SimpleFontData* fontData, - bool recurse) -{ - HDC dc = GetDC((HWND)0); - HGDIOBJ old_font = SelectObject(dc, fontData->m_font.hfont()); - - TEXTMETRIC tm = {0}; - if (!GetTextMetrics(dc, &tm)) { - SelectObject(dc, old_font); - ReleaseDC(0, dc); - - if (recurse) { - if (ChromiumBridge::ensureFontLoaded(fontData->m_font.hfont())) { - return fillBMPGlyphs(buffer, page, fontData, false); - } else { - fillEmptyGlyphs(page); - return false; - } - } else { - // TODO(nsylvain): This should never happen. We want to crash the - // process and receive a crash dump. We should revisit this code later. - // See bug 1136944. - ASSERT_NOT_REACHED(); - fillEmptyGlyphs(page); - return false; - } - } - - // NOTE(hbono): GetGlyphIndices() sets each item of localGlyphBuffer[] - // with the one of the values listed below. - // * With the GGI_MARK_NONEXISTING_GLYPHS flag - // + If the font has a glyph available for the character, - // localGlyphBuffer[i] > 0x0. - // + If the font does not have glyphs available for the character, - // localGlyphBuffer[i] = 0x1F (TrueType Collection?) or - // 0xFFFF (OpenType?). - // * Without the GGI_MARK_NONEXISTING_GLYPHS flag - // + If the font has a glyph available for the character, - // localGlyphBuffer[i] > 0x0. - // + If the font does not have glyphs available for the character, - // localGlyphBuffer[i] = 0x80. - // (Windows automatically assigns the glyph for a box character to - // prevent ExtTextOut() from returning errors.) - // To avoid from hurting the rendering performance, this code just - // tells WebKit whether or not the all glyph indices for the given - // characters are 0x80 (i.e. a possibly-invalid glyph) and let it - // use alternative fonts for the characters. - // Although this may cause a problem, it seems to work fine as far as I - // have tested. (Obviously, I need more tests.) - WORD localGlyphBuffer[GlyphPage::size]; - - // NOTE(jnd). I find some Chinese characters can not be correctly displayed - // when call GetGlyphIndices without flag GGI_MARK_NONEXISTING_GLYPHS, - // because the corresponding glyph index is set as 0x20 when current font - // does not have glyphs available for the character. According a blog post - // http://blogs.msdn.com/michkap/archive/2006/06/28/649791.aspx - // I think we should switch to the way about calling GetGlyphIndices with - // flag GGI_MARK_NONEXISTING_GLYPHS, it should be OK according the - // description of MSDN. - // Also according to Jungshik and Hironori's suggestion and modification - // we treat turetype and raster Font as different way when windows version - // is less than Vista. - GetGlyphIndices(dc, buffer, GlyphPage::size, localGlyphBuffer, - GGI_MARK_NONEXISTING_GLYPHS); - - // Copy the output to the GlyphPage - bool have_glyphs = false; - int invalid_glyph = 0xFFFF; - if (!ChromiumUtils::isVistaOrGreater() && !(tm.tmPitchAndFamily & TMPF_TRUETYPE)) - invalid_glyph = 0x1F; - - Glyph space_glyph = 0; // Glyph for a space. Lazily filled. - - for (unsigned i = 0; i < GlyphPage::size; i++) { - UChar c = buffer[i]; - Glyph glyph = localGlyphBuffer[i]; - const SimpleFontData* glyphFontData = fontData; - // When this character should be a space, we ignore whatever the font - // says and use a space. Otherwise, if fonts don't map one of these - // space or zero width glyphs, we will get a box. - if (Font::treatAsSpace(c)) { - // Hard code the glyph indices for characters that should be - // treated like spaces. - glyph = initSpaceGlyph(dc, &space_glyph); - // TODO(dglazkov): change Font::treatAsZeroWidthSpace to use - // u_hasBinaryProperty, per jungshik's comment here: - // https://bugs.webkit.org/show_bug.cgi?id=20237#c6. - // Then the additional OR won't be necessary. - } else if (Font::treatAsZeroWidthSpace(c) || c == 0x200B) { - glyph = initSpaceGlyph(dc, &space_glyph); - glyphFontData = fontData->zeroWidthFontData(); - } else if (glyph == invalid_glyph) { - // WebKit expects both the glyph index and FontData - // pointer to be NULL if the glyph is not present - glyph = 0; - glyphFontData = 0; - } else { - if (SimpleFontData::isCJKCodePoint(c)) - glyphFontData = fontData->cjkWidthFontData(); - have_glyphs = true; - } - page->setGlyphDataForCharacter(i, glyph, glyphFontData); - } - - SelectObject(dc, old_font); - ReleaseDC(0, dc); - return have_glyphs; -} - -// For non-BMP characters, each is two words (UTF-16) and the input buffer size -// is (GlyphPage::size * 1). Since GDI doesn't know how to handle non-BMP -// characters, we must use Uniscribe to tell us the glyph indices. -// -// We don't want to call this in the case of "regular" characters since some -// fonts may not have the correct combining rules for accents. See the notes -// at the bottom of ScriptGetCMap. We can't use ScriptGetCMap, though, since -// it doesn't seem to support UTF-16, despite what this blog post says: -// http://blogs.msdn.com/michkap/archive/2006/06/29/650680.aspx -// -// So we fire up the full Uniscribe doohicky, give it our string, and it will -// correctly handle the UTF-16 for us. The hard part is taking this and getting -// the glyph indices back out that correspond to the correct input characters, -// since they may be missing. -// -// Returns true if any glyphs were found. -static bool fillNonBMPGlyphs(UChar* buffer, - GlyphPage* page, - const SimpleFontData* fontData) -{ - bool haveGlyphs = false; - - UniscribeHelperTextRun state(buffer, GlyphPage::size * 2, false, - fontData->m_font.hfont(), - fontData->m_font.scriptCache(), - fontData->m_font.scriptFontProperties()); - state.setInhibitLigate(true); - state.Init(); - - for (unsigned i = 0; i < GlyphPage::size; i++) { - // Each character in this input buffer is a surrogate pair, which - // consists of two UChars. So, the offset for its i-th character is - // (i * 2). - WORD glyph = state.FirstGlyphForCharacter(i * 2); - if (glyph) { - haveGlyphs = true; - page->setGlyphDataForIndex(i, glyph, fontData); - } else { - // Clear both glyph and fontData fields. - page->setGlyphDataForIndex(i, 0, 0); - } - } - return haveGlyphs; -} - -// We're supposed to return true if there are any glyphs in this page in our -// font, false if there are none. -bool GlyphPage::fill(unsigned offset, unsigned length, UChar* characterBuffer, - unsigned bufferLength, const SimpleFontData* fontData) -{ - // This function's parameters are kind of stupid. We always fill this page, - // which is a fixed size. The source character indices are in the given - // input buffer. For non-BMP characters each character will be represented - // by a surrogate pair (two characters), so the input bufferLength will be - // twice as big, even though the output size is the same. - // - // We have to handle BMP and non-BMP characters differently anyway... - if (bufferLength == GlyphPage::size) { - return fillBMPGlyphs(characterBuffer, this, fontData, true); - } else if (bufferLength == GlyphPage::size * 2) { - return fillNonBMPGlyphs(characterBuffer, this, fontData); - } else { - // TODO: http://b/1007391 make use of offset and length - return false; - } -} - -} // namespace WebCore diff --git a/webkit/port/platform/graphics/chromium/GlyphPageTreeNodeLinux.cpp b/webkit/port/platform/graphics/chromium/GlyphPageTreeNodeLinux.cpp deleted file mode 100644 index 65b02c7..0000000 --- a/webkit/port/platform/graphics/chromium/GlyphPageTreeNodeLinux.cpp +++ /dev/null @@ -1,72 +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 "GlyphPageTreeNode.h" - -#include "Font.h" -#include "NotImplemented.h" -#include "SimpleFontData.h" - -#include "SkTemplates.h" -#include "SkPaint.h" -#include "SkUtils.h" - -namespace WebCore -{ - -bool GlyphPage::fill(unsigned offset, unsigned length, UChar* buffer, unsigned bufferLength, const SimpleFontData* fontData) -{ - if (SkUTF16_IsHighSurrogate(buffer[bufferLength-1])) { - SkDebugf("%s last char is high-surrogate", __FUNCTION__); - return false; - } - - SkPaint paint; - fontData->platformData().setupPaint(&paint); - paint.setTextEncoding(SkPaint::kUTF16_TextEncoding); - - SkAutoSTMalloc <GlyphPage::size, uint16_t> glyphStorage(length); - uint16_t* glyphs = glyphStorage.get(); - // textToGlyphs takes a byte count, not a glyph count so we multiply by two. - unsigned count = paint.textToGlyphs(buffer, bufferLength * 2, glyphs); - if (count != length) { - SkDebugf("%s count != length\n", __FUNCTION__); - return false; - } - - unsigned allGlyphs = 0; // track if any of the glyphIDs are non-zero - for (unsigned i = 0; i < length; i++) { - setGlyphDataForIndex(offset + i, glyphs[i], glyphs[i] ? fontData : NULL); - allGlyphs |= glyphs[i]; - } - return allGlyphs != 0; -} - -} // namespace WebCore diff --git a/webkit/port/platform/graphics/chromium/IconChromiumLinux.cpp b/webkit/port/platform/graphics/chromium/IconChromiumLinux.cpp deleted file mode 100644 index 9c38d84..0000000 --- a/webkit/port/platform/graphics/chromium/IconChromiumLinux.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* -* Copyright (C) 2006, 2007 Apple Inc. -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU Library General Public -* License as published by the Free Software Foundation; either -* version 2 of the License, or (at your option) any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* Library General Public License for more details. -* -* You should have received a copy of the GNU Library General Public License -* along with this library; see the file COPYING.LIB. If not, write to -* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -* Boston, MA 02111-1307, USA. -* -*/ - -#include "config.h" - -#include "Icon.h" - -#include "GraphicsContext.h" -#include "NotImplemented.h" -#include "PlatformString.h" -#include "SkiaUtils.h" - -namespace WebCore { - -Icon::Icon(const PlatformIcon& icon) - : m_icon(icon) -{ -} - -Icon::~Icon() -{ -} - -PassRefPtr<Icon> Icon::createIconForFile(const String& filename) -{ - notImplemented(); - return NULL; -} - -PassRefPtr<Icon> Icon::createIconForFiles(const Vector<String>& filenames) -{ - notImplemented(); - return NULL; -} - -void Icon::paint(GraphicsContext* context, const IntRect& r) -{ - notImplemented(); -} - -} // namespace WebCore diff --git a/webkit/port/platform/graphics/chromium/IconChromiumMac.cpp b/webkit/port/platform/graphics/chromium/IconChromiumMac.cpp deleted file mode 100644 index 6514d71..0000000 --- a/webkit/port/platform/graphics/chromium/IconChromiumMac.cpp +++ /dev/null @@ -1,59 +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 "Icon.h" -#include "PassRefPtr.h" - -// TODO(port): These are temporary stubs, we need real implementations which -// may come in the form of IconChromium.cpp. The Windows Chromium -// implementation is currently in IconWin.cpp. - -namespace WebCore { - -PassRefPtr<Icon> Icon::createIconForFile(const String& filename) -{ - return NULL; -} - -PassRefPtr<Icon> Icon::createIconForFiles(const Vector<String>& filenames) -{ - return NULL; -} - -Icon::~Icon() -{ -} - -void Icon::paint(GraphicsContext* context, const IntRect& rect) -{ -} - -} diff --git a/webkit/port/platform/graphics/chromium/IconChromiumWin.cpp b/webkit/port/platform/graphics/chromium/IconChromiumWin.cpp deleted file mode 100644 index 4d640cc..0000000 --- a/webkit/port/platform/graphics/chromium/IconChromiumWin.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* -* Copyright (C) 2006, 2007 Apple Inc. -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU Library General Public -* License as published by the Free Software Foundation; either -* version 2 of the License, or (at your option) any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* Library General Public License for more details. -* -* You should have received a copy of the GNU Library General Public License -* along with this library; see the file COPYING.LIB. If not, write to -* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -* Boston, MA 02111-1307, USA. -* -*/ - -#include "config.h" - -#include <windows.h> -#include <shellapi.h> - -#include "GraphicsContext.h" -#include "Icon.h" -#include "PlatformContextSkia.h" -#include "PlatformString.h" -#include "SkiaUtils.h" - -namespace WebCore { - -Icon::Icon(const PlatformIcon& icon) - : m_icon(icon) -{ -} - -Icon::~Icon() -{ - if (m_icon) - DestroyIcon(m_icon); -} - -PassRefPtr<Icon> Icon::createIconForFile(const String& filename) -{ - SHFILEINFO sfi; - memset(&sfi, 0, sizeof(sfi)); - - String tmpFilename = filename; - if (!SHGetFileInfo(tmpFilename.charactersWithNullTermination(), 0, &sfi, sizeof(sfi), SHGFI_ICON | SHGFI_SHELLICONSIZE | SHGFI_SMALLICON)) - return 0; - - return adoptRef(new Icon(sfi.hIcon)); -} - -PassRefPtr<Icon> Icon::createIconForFiles(const Vector<String>& filenames) -{ - // TODO: support multiple files. - // http://code.google.com/p/chromium/issues/detail?id=4092 - if (!filenames.size()) - return 0; - - return createIconForFile(filenames[0]); -} - -void Icon::paint(GraphicsContext* context, const IntRect& rect) -{ - if (context->paintingDisabled()) - return; - - HDC hdc = context->platformContext()->canvas()->beginPlatformPaint(); - DrawIconEx(hdc, rect.x(), rect.y(), m_icon, rect.width(), rect.height(), - 0, 0, DI_NORMAL); - context->platformContext()->canvas()->endPlatformPaint(); -} - -} // namespace WebCore diff --git a/webkit/port/platform/graphics/chromium/ImageBufferData.h b/webkit/port/platform/graphics/chromium/ImageBufferData.h deleted file mode 100644 index f8d3fd3..0000000 --- a/webkit/port/platform/graphics/chromium/ImageBufferData.h +++ /dev/null @@ -1,56 +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: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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. - */ - -#ifndef ImageBufferData_h -#define ImageBufferData_h - -#if PLATFORM(DARWIN) -// TODO(port): This #include isn't strictly kosher, but we're currently using -// the Mac font code from upstream WebKit, and we need to pick up their header. -#undef ImageBufferData_h -#include "third_party/WebKit/WebCore/platform/graphics/cg/ImageBufferData.h" -#else - -#include "PlatformContextSkia.h" - -#include "skia/ext/platform_canvas.h" - -namespace WebCore { - -class ImageBufferData { -public: - ImageBufferData(const IntSize&); - - skia::PlatformCanvas m_canvas; - - // Must be second since this will refer to m_canvas. - PlatformContextSkia m_platformContext; -}; - -} // namespace WebCore - -#endif - -#endif // ImageBufferData_h diff --git a/webkit/port/platform/graphics/chromium/ImageChromiumMac.mm b/webkit/port/platform/graphics/chromium/ImageChromiumMac.mm deleted file mode 100644 index c2a3555..0000000 --- a/webkit/port/platform/graphics/chromium/ImageChromiumMac.mm +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// A wrapper around Uniscribe that provides a reasonable API. - -#include "config.h" - -#include "BitmapImage.h" -#include "ChromiumBridge.h" -#include "Image.h" - - -namespace WebCore { - -PassRefPtr<Image> Image::loadPlatformResource(const char* name) -{ - return ChromiumBridge::loadPlatformImageResource(name); -} - -// TODO(port): These are temporary stubs, we need real implementations which -// may come in the form of ImageChromium.cpp. The Windows Chromium -// implementation is currently in ImageSkia.cpp. - -void BitmapImage::initPlatformData() -{ -} - -void BitmapImage::invalidatePlatformData() -{ -} - -} diff --git a/webkit/port/platform/graphics/chromium/MediaPlayerPrivateChromium.h b/webkit/port/platform/graphics/chromium/MediaPlayerPrivateChromium.h deleted file mode 100644 index 082b6ab..0000000 --- a/webkit/port/platform/graphics/chromium/MediaPlayerPrivateChromium.h +++ /dev/null @@ -1,98 +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. - -#ifndef MediaPlayerPrivateChromium_h -#define MediaPlayerPrivateChromium_h - -#if ENABLE(VIDEO) - -#include "MediaPlayer.h" - -namespace WebCore { - - class MediaPlayerPrivate : public Noncopyable { - public: - MediaPlayerPrivate(MediaPlayer*); - ~MediaPlayerPrivate(); - - IntSize naturalSize() const; - bool hasVideo() const; - - void load(const String& url); - void cancelLoad(); - - void play(); - void pause(); - - bool paused() const; - bool seeking() const; - - float duration() const; - float currentTime() const; - void seek(float time); - void setEndTime(float); - - void setRate(float); - void setVolume(float); - - int dataRate() const; - - MediaPlayer::NetworkState networkState() const; - MediaPlayer::ReadyState readyState() const; - - float maxTimeBuffered() const; - float maxTimeSeekable() const; - unsigned bytesLoaded() const; - bool totalBytesKnown() const; - unsigned totalBytes() const; - - void setVisible(bool); - void setRect(const IntRect&); - - void paint(GraphicsContext*, const IntRect&); - - static void getSupportedTypes(HashSet<String>& types); - static bool isAvailable(); - - // Public methods to be called by WebMediaPlayer - FrameView* frameView(); - void networkStateChanged(); - void readyStateChanged(); - void timeChanged(); - void volumeChanged(); - void repaint(); - - private: - MediaPlayer* m_player; - void* m_data; - }; -} - -#endif - -#endif // MediaPlayerPrivateChromium_h diff --git a/webkit/port/platform/graphics/chromium/PlatformIcon.h b/webkit/port/platform/graphics/chromium/PlatformIcon.h deleted file mode 100644 index 9bbd548..0000000 --- a/webkit/port/platform/graphics/chromium/PlatformIcon.h +++ /dev/null @@ -1,41 +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. - -#ifndef PlatformIcon_h -#define PlatformIcon_h - -typedef struct HICON__* HICON; - -namespace WebCore { - -typedef HICON PlatformIcon; - -} - -#endif diff --git a/webkit/port/platform/graphics/chromium/SimpleFontDataChromiumWin.cpp b/webkit/port/platform/graphics/chromium/SimpleFontDataChromiumWin.cpp deleted file mode 100644 index 6be0a1e..0000000 --- a/webkit/port/platform/graphics/chromium/SimpleFontDataChromiumWin.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (C) 2006, 2007 Apple 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: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "ChromiumBridge.h" -#include "Font.h" -#include "FontCache.h" -#include "SimpleFontData.h" -#include "FloatRect.h" -#include "FontDescription.h" -#include <wtf/MathExtras.h> -#include <unicode/uchar.h> -#include <unicode/unorm.h> -#include <objidl.h> -#include <mlang.h> - -namespace WebCore { - -static inline float scaleEmToUnits(float x, int unitsPerEm) -{ - return unitsPerEm ? x / (float)unitsPerEm : x; -} - -void SimpleFontData::platformInit() -{ - HDC dc = GetDC(0); - HGDIOBJ oldFont = SelectObject(dc, m_font.hfont()); - - TEXTMETRIC tm = {0}; - if (!GetTextMetrics(dc, &tm)) { - if (ChromiumBridge::ensureFontLoaded(m_font.hfont())) { - // Retry GetTextMetrics. - // TODO(nsylvain): Handle gracefully the error if this call also - // fails. - // See bug 1136944. - if (!GetTextMetrics(dc, &tm)) { - ASSERT_NOT_REACHED(); - } - } - } - - m_avgCharWidth = tm.tmAveCharWidth; - m_maxCharWidth = tm.tmMaxCharWidth; - - 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; - - SelectObject(dc, oldFont); - ReleaseDC(0, dc); -} - -void SimpleFontData::platformDestroy() -{ - // We don't hash this on Win32, so it's effectively owned by us. - delete m_smallCapsFontData; - m_smallCapsFontData = NULL; -} - -SimpleFontData* SimpleFontData::smallCapsFontData(const FontDescription& fontDescription) const -{ - if (!m_smallCapsFontData) { - LOGFONT winfont; - GetObject(m_font.hfont(), sizeof(LOGFONT), &winfont); - float smallCapsSize = 0.70f * fontDescription.computedSize(); - // Unlike WebKit trunk, we don't multiply the size by 32. That seems - // to be some kind of artifact of their CG backend, or something. - winfont.lfHeight = -lroundf(smallCapsSize); - HFONT hfont = CreateFontIndirect(&winfont); - m_smallCapsFontData = - new SimpleFontData(FontPlatformData(hfont, smallCapsSize)); - } - return m_smallCapsFontData; -} - -bool SimpleFontData::containsCharacters(const UChar* characters, int length) const -{ - // This used to be implemented with IMLangFontLink2, but since that code has - // been disabled, this would always return false anyway. - return false; -} - -void SimpleFontData::determinePitch() -{ - // TEXTMETRICS have this. Set m_treatAsFixedPitch based off that. - HDC dc = GetDC((HWND)0); - HGDIOBJ oldFont = SelectObject(dc, m_font.hfont()); - - // Yes, this looks backwards, but the fixed pitch bit is actually set if the font - // is *not* fixed pitch. Unbelievable but true. - TEXTMETRIC tm = {0}; - if (!GetTextMetrics(dc, &tm)) { - if (ChromiumBridge::ensureFontLoaded(m_font.hfont())) { - // Retry GetTextMetrics. - // TODO(nsylvain): Handle gracefully the error if this call also fails. - // See bug 1136944. - if (!GetTextMetrics(dc, &tm)) { - ASSERT_NOT_REACHED(); - } - } - } - - m_treatAsFixedPitch = ((tm.tmPitchAndFamily & TMPF_FIXED_PITCH) == 0); - - SelectObject(dc, oldFont); - ReleaseDC(0, dc); -} - -float SimpleFontData::platformWidthForGlyph(Glyph glyph) const -{ - HDC dc = GetDC(0); - HGDIOBJ oldFont = SelectObject(dc, m_font.hfont()); - - int width = 0; - if (!GetCharWidthI(dc, glyph, 1, 0, &width)) { - // Ask the browser to preload the font and retry. - if (ChromiumBridge::ensureFontLoaded(m_font.hfont())) { - if (!GetCharWidthI(dc, glyph, 1, 0, &width)) { - ASSERT_NOT_REACHED(); - } - } - } - - SelectObject(dc, oldFont); - ReleaseDC(0, dc); - - return static_cast<float>(width); -} - -} diff --git a/webkit/port/platform/graphics/chromium/SimpleFontDataLinux.cpp b/webkit/port/platform/graphics/chromium/SimpleFontDataLinux.cpp deleted file mode 100644 index 150e7c5..0000000 --- a/webkit/port/platform/graphics/chromium/SimpleFontDataLinux.cpp +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "config.h" -#include "SimpleFontData.h" - -#include "Font.h" -#include "FontCache.h" -#include "FloatRect.h" -#include "FontDescription.h" -#include "Logging.h" -#include "NotImplemented.h" - -#include "SkPaint.h" -#include "SkTypeface.h" -#include "SkTime.h" - -namespace WebCore { - -// Smallcaps versions of fonts are 70% the size of the normal font. -static const float kSmallCapsFraction = 0.7f; - -void SimpleFontData::platformInit() -{ - SkPaint paint; - SkPaint::FontMetrics metrics; - - m_font.setupPaint(&paint); - paint.getFontMetrics(&metrics); - - // Beware those who step here: This code is designed to match Win32 font - // metrics *exactly*. - if (metrics.fVDMXMetricsValid) { - m_ascent = metrics.fVDMXAscent; - m_descent = metrics.fVDMXDescent; - } else { - m_ascent = SkScalarRound(-metrics.fAscent); - m_descent = SkScalarRound(metrics.fHeight) - m_ascent; - } - - if (metrics.fXHeight) { - m_xHeight = metrics.fXHeight; - } else { - // hack taken from the Windows port - m_xHeight = static_cast<float>(m_ascent) * 0.56; - } - - m_lineGap = SkScalarRound(metrics.fLeading); - m_lineSpacing = m_ascent + m_descent + m_lineGap; - - // In WebKit/WebCore/platform/graphics/SimpleFontData.cpp, m_spaceWidth is - // calculated for us, but we need to calculate m_maxCharWidth and - // m_avgCharWidth in order for text entry widgets to be sized correctly. - - m_maxCharWidth = SkScalarRound(metrics.fXRange * SkScalarRound(m_font.size())); - - if (metrics.fAvgCharWidth) { - m_avgCharWidth = SkScalarRound(metrics.fAvgCharWidth); - } else { - m_avgCharWidth = m_xHeight; - - GlyphPage* glyphPageZero = GlyphPageTreeNode::getRootChild(this, 0)->page(); - - if (glyphPageZero) { - static const UChar32 x_char = 'x'; - const Glyph x_glyph = glyphPageZero->glyphDataForCharacter(x_char).glyph; - - if (x_glyph) { - m_avgCharWidth = widthForGlyph(x_glyph); - } - } - } -} - -void SimpleFontData::platformDestroy() -{ - delete m_smallCapsFontData; -} - -SimpleFontData* SimpleFontData::smallCapsFontData(const FontDescription& fontDescription) const -{ - if (!m_smallCapsFontData) { - const float smallCapsSize = lroundf(fontDescription.computedSize() * kSmallCapsFraction); - m_smallCapsFontData = - new SimpleFontData(FontPlatformData(m_font, smallCapsSize)); - } - return m_smallCapsFontData; -} - -bool SimpleFontData::containsCharacters(const UChar* characters, int length) const -{ - SkPaint paint; - static const unsigned kMaxBufferCount = 64; - uint16_t glyphs[kMaxBufferCount]; - - m_font.setupPaint(&paint); - paint.setTextEncoding(SkPaint::kUTF16_TextEncoding); - - while (length > 0) { - int n = SkMin32(length, SK_ARRAY_COUNT(glyphs)); - - // textToGlyphs takes a byte count so we double the character count. - int count = paint.textToGlyphs(characters, n * 2, glyphs); - for (int i = 0; i < count; i++) { - if (0 == glyphs[i]) { - return false; // missing glyph - } - } - - characters += n; - length -= n; - } - return true; -} - -void SimpleFontData::determinePitch() -{ - m_treatAsFixedPitch = platformData().isFixedPitch(); -} - -float SimpleFontData::platformWidthForGlyph(Glyph glyph) const -{ - SkASSERT(sizeof(glyph) == 2); // compile-time assert - - SkPaint paint; - - m_font.setupPaint(&paint); - - paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); - SkScalar width = paint.measureText(&glyph, 2); - - return SkScalarToFloat(width); -} - -} // namespace WebCore diff --git a/webkit/port/platform/graphics/chromium/ThemeHelperChromiumWin.cpp b/webkit/port/platform/graphics/chromium/ThemeHelperChromiumWin.cpp deleted file mode 100644 index 4461d3c..0000000 --- a/webkit/port/platform/graphics/chromium/ThemeHelperChromiumWin.cpp +++ /dev/null @@ -1,102 +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: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "ThemeHelperChromiumWin.h" - -#include "FloatRect.h" -#include "GraphicsContext.h" - -namespace WebCore { - -ThemeHelperWin::ThemeHelperWin(GraphicsContext* context, - const IntRect& rect) - : m_orgContext(context) - , m_orgMatrix(context->getCTM()) - , m_orgRect(rect) -{ - if (m_orgMatrix.b() != 0 || // Y skew - m_orgMatrix.c() != 0) { // X skew - // Complicated effects, make a copy and draw the bitmap there. - m_type = COPY; - m_rect.setSize(rect.size()); - - m_newBuffer.set(ImageBuffer::create(rect.size(), false).release()); - - // Theme drawing messes with the transparency. - // TODO(brettw) Ideally, we would leave this transparent, but I was - // having problems with button drawing, so we fill with white. Buttons - // looked good with transparent here and no fixing up of the alpha - // later, but text areas didn't. This makes text areas look good but - // gives buttons a white halo. Is there a way to fix this? I think - // buttons actually have antialised edges which is just not possible - // to handle on a transparent background given that it messes with the - // alpha channel. - FloatRect newContextRect(0, 0, rect.width(), rect.height()); - GraphicsContext* newContext = m_newBuffer->context(); - newContext->setFillColor(Color::white); - newContext->fillRect(newContextRect); - - return; - } - - if (m_orgMatrix.a() != 1.0 || // X scale - m_orgMatrix.d() != 1.0) { // Y scale - // Only a scaling is applied. - m_type = SCALE; - - // Save the transformed coordinates to draw. - m_rect = m_orgMatrix.mapRect(rect); - - m_orgContext->save(); - m_orgContext->concatCTM(m_orgContext->getCTM().inverse()); - return; - } - - // Nothing interesting. - m_rect = rect; - m_type = ORIGINAL; -} - -ThemeHelperWin::~ThemeHelperWin() -{ - switch (m_type) { - case SCALE: - m_orgContext->restore(); - break; - case COPY: { - // Copy the duplicate bitmap with our control to the original canvas. - FloatRect destRect(m_orgRect); - m_newBuffer->context()->platformContext()->canvas()-> - getTopPlatformDevice().fixupAlphaBeforeCompositing(); - m_orgContext->drawImage(m_newBuffer->image(), destRect); - break; - } - case ORIGINAL: - break; - } -} - -} // namespace WebCore diff --git a/webkit/port/platform/graphics/chromium/ThemeHelperChromiumWin.h b/webkit/port/platform/graphics/chromium/ThemeHelperChromiumWin.h deleted file mode 100644 index 6141824..0000000 --- a/webkit/port/platform/graphics/chromium/ThemeHelperChromiumWin.h +++ /dev/null @@ -1,93 +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: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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. - */ - -#ifndef ThemeHelperWin_h -#define ThemeHelperWin_h - -#include "AffineTransform.h" -#include "ImageBuffer.h" -#include "IntRect.h" -#include "WTF/OwnPtr.h" - -namespace WebCore { - -class GraphicsContext; -class IntRect; - -// Helps drawing theme elements like buttons and scroll bars. This will handle -// translations and scalings that Windows might not, by either making Windows -// draw the appropriate sized control, or by rendering it into an off-screen -// context and transforming it ourselves. -class ThemeHelperWin { - enum Type { - // Use the original canvas with no changes. This is the normal mode. - ORIGINAL, - - // Use the original canvas but scale the rectangle of the control so - // that it will be the correct size, undoing any scale already on the - // canvas. This will have the effect of just drawing the control bigger - // or smaller and not actually expanding or contracting the pixels in - // it. This usually looks better. - SCALE, - - // Make a copy of the control and then transform it ourselves after - // Windows draws it. This allows us to get complex effects. - COPY, - }; - -public: - // Prepares drawing a control with the given rect to the given context. - ThemeHelperWin(GraphicsContext* context, const IntRect& rect); - ~ThemeHelperWin(); - - // Returns the context to draw the control into, which may be the original - // or the copy, depending on the mode. - GraphicsContext* context() - { - return m_newBuffer.get() ? m_newBuffer->context() : m_orgContext; - } - - // Returns the rectangle in which to draw into the canvas() by Windows. - const IntRect& rect() { return m_rect; } - -private: - Type m_type; - - // The original canvas to wrote to. Not owned by this class. - GraphicsContext* m_orgContext; - AffineTransform m_orgMatrix; - IntRect m_orgRect; - - // When m_type == COPY, this will be a new surface owned by this class that - // represents the copy. - OwnPtr<ImageBuffer> m_newBuffer; - - // The control rectangle in the coordinate space of canvas(). - IntRect m_rect; -}; - -} // namespace WebCore - -#endif // ThemeHelperWin_h diff --git a/webkit/port/platform/graphics/chromium/UniscribeHelper.cpp b/webkit/port/platform/graphics/chromium/UniscribeHelper.cpp deleted file mode 100644 index 1ace87a..0000000 --- a/webkit/port/platform/graphics/chromium/UniscribeHelper.cpp +++ /dev/null @@ -1,868 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "config.h" -#include "UniscribeHelper.h" - -#include <windows.h> - -#include "FontUtilsChromiumWin.h" -#include <wtf/Assertions.h> - -namespace WebCore { - -// This function is used to see where word spacing should be applied inside -// runs. Note that this must match Font::treatAsSpace so we all agree where -// and how much space this is, so we don't want to do more general Unicode -// "is this a word break" thing. -static bool TreatAsSpace(UChar c) -{ - return c == ' ' || c == '\t' || c == '\n' || c == 0x00A0; -} - -// SCRIPT_FONTPROPERTIES contains glyph indices for default, invalid -// and blank glyphs. Just because ScriptShape succeeds does not mean -// that a text run is rendered correctly. Some characters may be rendered -// with default/invalid/blank glyphs. Therefore, we need to check if the glyph -// array returned by ScriptShape contains any of those glyphs to make -// sure that the text run is rendered successfully. -static bool ContainsMissingGlyphs(WORD *glyphs, - int length, - SCRIPT_FONTPROPERTIES* properties) -{ - for (int i = 0; i < length; ++i) { - if (glyphs[i] == properties->wgDefault || - (glyphs[i] == properties->wgInvalid && - glyphs[i] != properties->wgBlank)) - return true; - } - - return false; -} - -// HFONT is the 'incarnation' of 'everything' about font, but it's an opaque -// handle and we can't directly query it to make a new HFONT sharing -// its characteristics (height, style, etc) except for family name. -// This function uses GetObject to convert HFONT back to LOGFONT, -// resets the fields of LOGFONT and calculates style to use later -// for the creation of a font identical to HFONT other than family name. -static void SetLogFontAndStyle(HFONT hfont, LOGFONT *logfont, int *style) -{ - ASSERT(hfont && logfont); - if (!hfont || !logfont) - return; - - GetObject(hfont, sizeof(LOGFONT), logfont); - // We reset these fields to values appropriate for CreateFontIndirect. - // while keeping lfHeight, which is the most important value in creating - // a new font similar to hfont. - logfont->lfWidth = 0; - logfont->lfEscapement = 0; - logfont->lfOrientation = 0; - logfont->lfCharSet = DEFAULT_CHARSET; - logfont->lfOutPrecision = OUT_TT_ONLY_PRECIS; - logfont->lfQuality = DEFAULT_QUALITY; // Honor user's desktop settings. - logfont->lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; - if (style) - *style = getStyleFromLogfont(logfont); -} - -UniscribeHelper::UniscribeHelper(const UChar* input, - int inputLength, - bool isRtl, - HFONT hfont, - SCRIPT_CACHE* scriptCache, - SCRIPT_FONTPROPERTIES* fontProperties) - : m_input(input) - , m_inputLength(inputLength) - , m_isRtl(isRtl) - , m_hfont(hfont) - , m_scriptCache(scriptCache) - , m_fontProperties(fontProperties) - , m_directionalOverride(false) - , m_inhibitLigate(false) - , m_letterSpacing(0) - , m_spaceWidth(0) - , m_wordSpacing(0) - , m_ascent(0) -{ - m_logfont.lfFaceName[0] = 0; -} - -UniscribeHelper::~UniscribeHelper() -{ -} - -void UniscribeHelper::InitWithOptionalLengthProtection(bool lengthProtection) -{ - // We cap the input length and just don't do anything. We'll allocate a lot - // of things of the size of the number of characters, so the allocated - // memory will be several times the input length. Plus shaping such a large - // buffer may be a form of denial of service. No legitimate text should be - // this long. It also appears that Uniscribe flatly rejects very long - // strings, so we don't lose anything by doing this. - // - // The input length protection may be disabled by the unit tests to cause - // an error condition. - static const int kMaxInputLength = 65535; - if (m_inputLength == 0 || - (lengthProtection && m_inputLength > kMaxInputLength)) - return; - - FillRuns(); - FillShapes(); - FillScreenOrder(); -} - -int UniscribeHelper::Width() const -{ - int width = 0; - for (int item_index = 0; item_index < static_cast<int>(m_runs.size()); - item_index++) { - width += AdvanceForItem(item_index); - } - return width; -} - -void UniscribeHelper::Justify(int additionalSpace) -{ - // Count the total number of glyphs we have so we know how big to make the - // buffers below. - int totalGlyphs = 0; - for (size_t run = 0; run < m_runs.size(); run++) { - int run_idx = m_screenOrder[run]; - totalGlyphs += static_cast<int>(m_shapes[run_idx].glyphLength()); - } - if (totalGlyphs == 0) - return; // Nothing to do. - - // We make one big buffer in screen order of all the glyphs we are drawing - // across runs so that the justification function will adjust evenly across - // all glyphs. - Vector<SCRIPT_VISATTR, 64> visattr; - visattr.resize(totalGlyphs); - Vector<int, 64> advances; - advances.resize(totalGlyphs); - Vector<int, 64> justify; - justify.resize(totalGlyphs); - - // Build the packed input. - int dest_index = 0; - for (size_t run = 0; run < m_runs.size(); run++) { - int run_idx = m_screenOrder[run]; - const Shaping& shaping = m_shapes[run_idx]; - - for (int i = 0; i < shaping.glyphLength(); i++, dest_index++) { - memcpy(&visattr[dest_index], &shaping.m_visattr[i], - sizeof(SCRIPT_VISATTR)); - advances[dest_index] = shaping.m_advance[i]; - } - } - - // The documentation for ScriptJustify is wrong, the parameter is the space - // to add and not the width of the column you want. - const int minKashida = 1; // How do we decide what this should be? - ScriptJustify(&visattr[0], &advances[0], totalGlyphs, additionalSpace, - minKashida, &justify[0]); - - // Now we have to unpack the justification amounts back into the runs so - // the glyph indices match. - int globalGlyphIndex = 0; - for (size_t run = 0; run < m_runs.size(); run++) { - int run_idx = m_screenOrder[run]; - Shaping& shaping = m_shapes[run_idx]; - - shaping.m_justify.resize(shaping.glyphLength()); - for (int i = 0; i < shaping.glyphLength(); i++, globalGlyphIndex++) - shaping.m_justify[i] = justify[globalGlyphIndex]; - } -} - -int UniscribeHelper::CharacterToX(int offset) const -{ - HRESULT hr; - ASSERT(offset <= m_inputLength); - - // Our algorithm is to traverse the items in screen order from left to - // right, adding in each item's screen width until we find the item with - // the requested character in it. - int width = 0; - for (size_t screen_idx = 0; screen_idx < m_runs.size(); screen_idx++) { - // Compute the length of this run. - int itemIdx = m_screenOrder[screen_idx]; - const SCRIPT_ITEM& item = m_runs[itemIdx]; - const Shaping& shaping = m_shapes[itemIdx]; - int itemLength = shaping.charLength(); - - if (offset >= item.iCharPos && offset <= item.iCharPos + itemLength) { - // Character offset is in this run. - int char_len = offset - item.iCharPos; - - int curX = 0; - hr = ScriptCPtoX(char_len, FALSE, itemLength, - shaping.glyphLength(), - &shaping.m_logs[0], &shaping.m_visattr[0], - shaping.effectiveAdvances(), &item.a, &curX); - if (FAILED(hr)) - return 0; - - width += curX + shaping.m_prePadding; - ASSERT(width >= 0); - return width; - } - - // Move to the next item. - width += AdvanceForItem(itemIdx); - } - ASSERT(width >= 0); - return width; -} - -int UniscribeHelper::XToCharacter(int x) const -{ - // We iterate in screen order until we find the item with the given pixel - // position in it. When we find that guy, we ask Uniscribe for the - // character index. - HRESULT hr; - for (size_t screen_idx = 0; screen_idx < m_runs.size(); screen_idx++) { - int itemIdx = m_screenOrder[screen_idx]; - int advance_for_item = AdvanceForItem(itemIdx); - - // Note that the run may be empty if shaping failed, so we want to skip - // over it. - const Shaping& shaping = m_shapes[itemIdx]; - int itemLength = shaping.charLength(); - if (x <= advance_for_item && itemLength > 0) { - // The requested offset is within this item. - const SCRIPT_ITEM& item = m_runs[itemIdx]; - - // Account for the leading space we've added to this run that - // Uniscribe doesn't know about. - x -= shaping.m_prePadding; - - int char_x = 0; - int trailing; - hr = ScriptXtoCP(x, itemLength, shaping.glyphLength(), - &shaping.m_logs[0], &shaping.m_visattr[0], - shaping.effectiveAdvances(), &item.a, &char_x, - &trailing); - - // The character offset is within the item. We need to add the - // item's offset to transform it into the space of the TextRun - return char_x + item.iCharPos; - } - - // The offset is beyond this item, account for its length and move on. - x -= advance_for_item; - } - - // Error condition, we don't know what to do if we don't have that X - // position in any of our items. - return 0; -} - -void UniscribeHelper::Draw(HDC dc, int x, int y, int from, int to) -{ - HGDIOBJ oldFont = 0; - int curX = x; - bool firstRun = true; - - for (size_t screen_idx = 0; screen_idx < m_runs.size(); screen_idx++) { - int itemIdx = m_screenOrder[screen_idx]; - const SCRIPT_ITEM& item = m_runs[itemIdx]; - const Shaping& shaping = m_shapes[itemIdx]; - - // Character offsets within this run. THESE MAY NOT BE IN RANGE and may - // be negative, etc. The code below handles this. - int fromChar = from - item.iCharPos; - int to_char = to - item.iCharPos; - - // See if we need to draw any characters in this item. - if (shaping.charLength() == 0 || - fromChar >= shaping.charLength() || to_char <= 0) { - // No chars in this item to display. - curX += AdvanceForItem(itemIdx); - continue; - } - - // Compute the starting glyph within this span. |from| and |to| are - // global offsets that may intersect arbitrarily with our local run. - int fromGlyph, afterGlyph; - if (item.a.fRTL) { - // To compute the first glyph when going RTL, we use |to|. - if (to_char >= shaping.charLength()) { - // The end of the text is after (to the left) of us. - fromGlyph = 0; - } else { - // Since |to| is exclusive, the first character we draw on the - // left is actually the one right before (to the right) of - // |to|. - fromGlyph = shaping.m_logs[to_char - 1]; - } - - // The last glyph is actually the first character in the range. - if (fromChar <= 0) { - // The first character to draw is before (to the right) of this - // span, so draw all the way to the end. - afterGlyph = shaping.glyphLength(); - } else { - // We want to draw everything up until the character to the - // right of |from|. To the right is - 1, so we look that up - // (remember our character could be more than one glyph, so we - // can't look up our glyph and add one). - afterGlyph = shaping.m_logs[fromChar - 1]; - } - } else { - // Easy case, everybody agrees about directions. We only need to - // handle boundary conditions to get a range inclusive at the - // beginning, and exclusive at the ending. We have to do some - // computation to see the glyph one past the end. - fromGlyph = shaping.m_logs[fromChar < 0 ? 0 : fromChar]; - if (to_char >= shaping.charLength()) - afterGlyph = shaping.glyphLength(); - else - afterGlyph = shaping.m_logs[to_char]; - } - - // Account for the characters that were skipped in this run. When - // WebKit asks us to draw a subset of the run, it actually tells us - // to draw at the X offset of the beginning of the run, since it - // doesn't know the internal position of any of our characters. - const int* effectiveAdvances = shaping.effectiveAdvances(); - int innerOffset = 0; - for (int i = 0; i < fromGlyph; i++) - innerOffset += effectiveAdvances[i]; - - // Actually draw the glyphs we found. - int glyphCount = afterGlyph - fromGlyph; - if (fromGlyph >= 0 && glyphCount > 0) { - // Account for the preceeding space we need to add to this run. We - // don't need to count for the following space because that will be - // counted in AdvanceForItem below when we move to the next run. - innerOffset += shaping.m_prePadding; - - // Pass NULL in when there is no justification. - const int* justify = shaping.m_justify.size() == 0 ? - NULL : &shaping.m_justify[fromGlyph]; - - if (firstRun) { - oldFont = SelectObject(dc, shaping.m_hfont); - firstRun = false; - } else { - SelectObject(dc, shaping.m_hfont); - } - - // TODO(brettw) bug 698452: if a half a character is selected, - // we should set up a clip rect so we draw the half of the glyph - // correctly. - // Fonts with different ascents can be used to render different - // runs. 'Across-runs' y-coordinate correction needs to be - // adjusted for each font. - HRESULT hr = S_FALSE; - for (int executions = 0; executions < 2; ++executions) { - hr = ScriptTextOut(dc, shaping.m_scriptCache, - curX + innerOffset, - y - shaping.m_ascentOffset, - 0, NULL, &item.a, NULL, 0, - &shaping.m_glyphs[fromGlyph], - glyphCount, - &shaping.m_advance[fromGlyph], - justify, - &shaping.m_offsets[fromGlyph]); - if (S_OK != hr && 0 == executions) { - // If this ScriptTextOut is called from the renderer it - // might fail because the sandbox is preventing it from - // opening the font files. If we are running in the - // renderer, TryToPreloadFont is overridden to ask the - // browser to preload the font for us so we can access it. - TryToPreloadFont(shaping.m_hfont); - continue; - } - break; - } - - ASSERT(S_OK == hr); - } - - curX += AdvanceForItem(itemIdx); - } - - if (oldFont) - SelectObject(dc, oldFont); -} - -WORD UniscribeHelper::FirstGlyphForCharacter(int charOffset) const -{ - // Find the run for the given character. - for (int i = 0; i < static_cast<int>(m_runs.size()); i++) { - int firstChar = m_runs[i].iCharPos; - const Shaping& shaping = m_shapes[i]; - int localOffset = charOffset - firstChar; - if (localOffset >= 0 && localOffset < shaping.charLength()) { - // The character is in this run, return the first glyph for it - // (should generally be the only glyph). It seems Uniscribe gives - // glyph 0 for empty, which is what we want to return in the - // "missing" case. - size_t glyphIndex = shaping.m_logs[localOffset]; - if (glyphIndex >= shaping.m_glyphs.size()) { - // The glyph should be in this run, but the run has too few - // actual characters. This can happen when shaping the run - // fails, in which case, we should have no data in the logs at - // all. - ASSERT(shaping.m_glyphs.size() == 0); - return 0; - } - return shaping.m_glyphs[glyphIndex]; - } - } - return 0; -} - -void UniscribeHelper::FillRuns() -{ - HRESULT hr; - m_runs.resize(UNISCRIBE_HELPER_STACK_RUNS); - - SCRIPT_STATE inputState; - inputState.uBidiLevel = m_isRtl; - inputState.fOverrideDirection = m_directionalOverride; - inputState.fInhibitSymSwap = false; - inputState.fCharShape = false; // Not implemented in Uniscribe - inputState.fDigitSubstitute = false; // Do we want this for Arabic? - inputState.fInhibitLigate = m_inhibitLigate; - inputState.fDisplayZWG = false; // Don't draw control characters. - inputState.fArabicNumContext = m_isRtl; // Do we want this for Arabic? - inputState.fGcpClusters = false; - inputState.fReserved = 0; - inputState.fEngineReserved = 0; - // The psControl argument to ScriptItemize should be non-NULL for RTL text, - // per http://msdn.microsoft.com/en-us/library/ms776532.aspx . So use a - // SCRIPT_CONTROL that is set to all zeros. Zero as a locale ID means the - // neutral locale per http://msdn.microsoft.com/en-us/library/ms776294.aspx - static SCRIPT_CONTROL inputControl = {0, // uDefaultLanguage :16; - 0, // fContextDigits :1; - 0, // fInvertPreBoundDir :1; - 0, // fInvertPostBoundDir :1; - 0, // fLinkStringBefore :1; - 0, // fLinkStringAfter :1; - 0, // fNeutralOverride :1; - 0, // fNumericOverride :1; - 0, // fLegacyBidiClass :1; - 0, // fMergeNeutralItems :1; - 0};// fReserved :7; - // Calling ScriptApplyDigitSubstitution( NULL, &inputControl, &inputState) - // here would be appropriate if we wanted to set the language ID, and get - // local digit substitution behavior. For now, don't do it. - - while (true) { - int num_items = 0; - - // Ideally, we would have a way to know the runs before and after this - // one, and put them into the control parameter of ScriptItemize. This - // would allow us to shape characters properly that cross style - // boundaries (WebKit bug 6148). - // - // We tell ScriptItemize that the output list of items is one smaller - // than it actually is. According to Mozilla bug 366643, if there is - // not enough room in the array on pre-SP2 systems, ScriptItemize will - // write one past the end of the buffer. - // - // ScriptItemize is very strange. It will often require a much larger - // ITEM buffer internally than it will give us as output. For example, - // it will say a 16-item buffer is not big enough, and will write - // interesting numbers into all those items. But when we give it a 32 - // item buffer and it succeeds, it only has one item output. - // - // It seems to be doing at least two passes, the first where it puts a - // lot of intermediate data into our items, and the second where it - // collates them. - hr = ScriptItemize(m_input, m_inputLength, - static_cast<int>(m_runs.size()) - 1, &inputControl, - &inputState, - &m_runs[0], &num_items); - if (SUCCEEDED(hr)) { - m_runs.resize(num_items); - break; - } - if (hr != E_OUTOFMEMORY) { - // Some kind of unexpected error. - m_runs.resize(0); - break; - } - // There was not enough items for it to write into, expand. - m_runs.resize(m_runs.size() * 2); - } -} - -bool UniscribeHelper::Shape(const UChar* input, - int itemLength, - int numGlyphs, - SCRIPT_ITEM& run, - Shaping& shaping) -{ - HFONT hfont = m_hfont; - SCRIPT_CACHE* scriptCache = m_scriptCache; - SCRIPT_FONTPROPERTIES* fontProperties = m_fontProperties; - int ascent = m_ascent; - HDC tempDC = NULL; - HGDIOBJ oldFont = 0; - HRESULT hr; - bool lastFallbackTried = false; - bool result; - - int generatedGlyphs = 0; - - // In case HFONT passed in ctor cannot render this run, we have to scan - // other fonts from the beginning of the font list. - ResetFontIndex(); - - // Compute shapes. - while (true) { - shaping.m_logs.resize(itemLength); - shaping.m_glyphs.resize(numGlyphs); - shaping.m_visattr.resize(numGlyphs); - - // Firefox sets SCRIPT_ANALYSIS.SCRIPT_STATE.fDisplayZWG to true - // here. Is that what we want? It will display control characters. - hr = ScriptShape(tempDC, scriptCache, input, itemLength, - numGlyphs, &run.a, - &shaping.m_glyphs[0], &shaping.m_logs[0], - &shaping.m_visattr[0], &generatedGlyphs); - if (hr == E_PENDING) { - // Allocate the DC. - tempDC = GetDC(NULL); - oldFont = SelectObject(tempDC, hfont); - continue; - } else if (hr == E_OUTOFMEMORY) { - numGlyphs *= 2; - continue; - } else if (SUCCEEDED(hr) && - (lastFallbackTried || - !ContainsMissingGlyphs(&shaping.m_glyphs[0], - generatedGlyphs, fontProperties))) { - break; - } - - // The current font can't render this run. clear DC and try - // next font. - if (tempDC) { - SelectObject(tempDC, oldFont); - ReleaseDC(NULL, tempDC); - tempDC = NULL; - } - - if (NextWinFontData(&hfont, &scriptCache, &fontProperties, &ascent)) { - // The primary font does not support this run. Try next font. - // In case of web page rendering, they come from fonts specified in - // CSS stylesheets. - continue; - } else if (!lastFallbackTried) { - lastFallbackTried = true; - - // Generate a last fallback font based on the script of - // a character to draw while inheriting size and styles - // from the primary font - if (!m_logfont.lfFaceName[0]) - SetLogFontAndStyle(m_hfont, &m_logfont, &m_style); - - // TODO(jungshik): generic type should come from webkit for - // UniscribeHelperTextRun (a derived class used in webkit). - const UChar *family = getFallbackFamily(input, itemLength, - FontDescription::StandardFamily, NULL, NULL); - bool font_ok = getDerivedFontData(family, m_style, &m_logfont, - &ascent, &hfont, &scriptCache); - - if (!font_ok) { - // If this GetDerivedFontData is called from the renderer it - // might fail because the sandbox is preventing it from opening - // the font files. If we are running in the renderer, - // TryToPreloadFont is overridden to ask the browser to preload - // the font for us so we can access it. - TryToPreloadFont(hfont); - - // Try again. - font_ok = getDerivedFontData(family, m_style, &m_logfont, - &ascent, &hfont, &scriptCache); - ASSERT(font_ok); - } - - // TODO(jungshik) : Currently GetDerivedHFont always returns a - // a valid HFONT, but in the future, I may change it to return 0. - ASSERT(hfont); - - // We don't need a font_properties for the last resort fallback font - // because we don't have anything more to try and are forced to - // accept empty glyph boxes. If we tried a series of fonts as - // 'last-resort fallback', we'd need it, but currently, we don't. - continue; - } else if (hr == USP_E_SCRIPT_NOT_IN_FONT) { - run.a.eScript = SCRIPT_UNDEFINED; - continue; - } else if (FAILED(hr)) { - // Error shaping. - generatedGlyphs = 0; - result = false; - goto cleanup; - } - } - - // Sets Windows font data for this run to those corresponding to - // a font supporting this run. we don't need to store font_properties - // because it's not used elsewhere. - shaping.m_hfont = hfont; - shaping.m_scriptCache = scriptCache; - - // The ascent of a font for this run can be different from - // that of the primary font so that we need to keep track of - // the difference per run and take that into account when calling - // ScriptTextOut in |Draw|. Otherwise, different runs rendered by - // different fonts would not be aligned vertically. - shaping.m_ascentOffset = m_ascent ? ascent - m_ascent : 0; - result = true; - - cleanup: - shaping.m_glyphs.resize(generatedGlyphs); - shaping.m_visattr.resize(generatedGlyphs); - shaping.m_advance.resize(generatedGlyphs); - shaping.m_offsets.resize(generatedGlyphs); - if (tempDC) { - SelectObject(tempDC, oldFont); - ReleaseDC(NULL, tempDC); - } - // On failure, our logs don't mean anything, so zero those out. - if (!result) - shaping.m_logs.clear(); - - return result; -} - -void UniscribeHelper::FillShapes() -{ - m_shapes.resize(m_runs.size()); - for (size_t i = 0; i < m_runs.size(); i++) { - int startItem = m_runs[i].iCharPos; - int itemLength = m_inputLength - startItem; - if (i < m_runs.size() - 1) - itemLength = m_runs[i + 1].iCharPos - startItem; - - int numGlyphs; - if (itemLength < UNISCRIBE_HELPER_STACK_CHARS) { - // We'll start our buffer sizes with the current stack space - // available in our buffers if the current input fits. As long as - // it doesn't expand past that we'll save a lot of time mallocing. - numGlyphs = UNISCRIBE_HELPER_STACK_CHARS; - } else { - // When the input doesn't fit, give up with the stack since it will - // almost surely not be enough room (unless the input actually - // shrinks, which is unlikely) and just start with the length - // recommended by the Uniscribe documentation as a "usually fits" - // size. - numGlyphs = itemLength * 3 / 2 + 16; - } - - // Convert a string to a glyph string trying the primary font, fonts in - // the fallback list and then script-specific last resort font. - Shaping& shaping = m_shapes[i]; - if (!Shape(&m_input[startItem], itemLength, numGlyphs, m_runs[i], - shaping)) - continue; - - // Compute placements. Note that offsets is documented incorrectly - // and is actually an array. - - // DC that we lazily create if Uniscribe commands us to. - // (this does not happen often because scriptCache is already - // updated when calling ScriptShape). - HDC tempDC = NULL; - HGDIOBJ oldFont = NULL; - HRESULT hr; - while (true) { - shaping.m_prePadding = 0; - hr = ScriptPlace(tempDC, shaping.m_scriptCache, - &shaping.m_glyphs[0], - static_cast<int>(shaping.m_glyphs.size()), - &shaping.m_visattr[0], &m_runs[i].a, - &shaping.m_advance[0], &shaping.m_offsets[0], - &shaping.m_abc); - if (hr != E_PENDING) - break; - - // Allocate the DC and run the loop again. - tempDC = GetDC(NULL); - oldFont = SelectObject(tempDC, shaping.m_hfont); - } - - if (FAILED(hr)) { - // Some error we don't know how to handle. Nuke all of our data - // since we can't deal with partially valid data later. - m_runs.clear(); - m_shapes.clear(); - m_screenOrder.clear(); - } - - if (tempDC) { - SelectObject(tempDC, oldFont); - ReleaseDC(NULL, tempDC); - } - } - - AdjustSpaceAdvances(); - - if (m_letterSpacing != 0 || m_wordSpacing != 0) - ApplySpacing(); -} - -void UniscribeHelper::FillScreenOrder() -{ - m_screenOrder.resize(m_runs.size()); - - // We assume that the input has only one text direction in it. - // TODO(brettw) are we sure we want to keep this restriction? - if (m_isRtl) { - for (int i = 0; i < static_cast<int>(m_screenOrder.size()); i++) - m_screenOrder[static_cast<int>(m_screenOrder.size()) - i - 1] = i; - } else { - for (int i = 0; i < static_cast<int>(m_screenOrder.size()); i++) - m_screenOrder[i] = i; - } -} - -void UniscribeHelper::AdjustSpaceAdvances() -{ - if (m_spaceWidth == 0) - return; - - int spaceWidthWithoutLetterSpacing = m_spaceWidth - m_letterSpacing; - - // This mostly matches what WebKit's UniscribeController::shapeAndPlaceItem. - for (size_t run = 0; run < m_runs.size(); run++) { - Shaping& shaping = m_shapes[run]; - - for (int i = 0; i < shaping.charLength(); i++) { - if (!TreatAsSpace(m_input[m_runs[run].iCharPos + i])) - continue; - - int glyphIndex = shaping.m_logs[i]; - int currentAdvance = shaping.m_advance[glyphIndex]; - // Don't give zero-width spaces a width. - if (!currentAdvance) - continue; - - // currentAdvance does not include additional letter-spacing, but - // space_width does. Here we find out how off we are from the - // correct width for the space not including letter-spacing, then - // just subtract that diff. - int diff = currentAdvance - spaceWidthWithoutLetterSpacing; - // The shaping can consist of a run of text, so only subtract the - // difference in the width of the glyph. - shaping.m_advance[glyphIndex] -= diff; - shaping.m_abc.abcB -= diff; - } - } -} - -void UniscribeHelper::ApplySpacing() -{ - for (size_t run = 0; run < m_runs.size(); run++) { - Shaping& shaping = m_shapes[run]; - bool isRtl = m_runs[run].a.fRTL; - - if (m_letterSpacing != 0) { - // RTL text gets padded to the left of each character. We increment - // the run's advance to make this happen. This will be balanced out - // by NOT adding additional advance to the last glyph in the run. - if (isRtl) - shaping.m_prePadding += m_letterSpacing; - - // Go through all the glyphs in this run and increase the "advance" - // to account for letter spacing. We adjust letter spacing only on - // cluster boundaries. - // - // This works for most scripts, but may have problems with some - // indic scripts. This behavior is better than Firefox or IE for - // Hebrew. - for (int i = 0; i < shaping.glyphLength(); i++) { - if (shaping.m_visattr[i].fClusterStart) { - // Ick, we need to assign the extra space so that the glyph - // comes first, then is followed by the space. This is - // opposite for RTL. - if (isRtl) { - if (i != shaping.glyphLength() - 1) { - // All but the last character just get the spacing - // applied to their advance. The last character - // doesn't get anything, - shaping.m_advance[i] += m_letterSpacing; - shaping.m_abc.abcB += m_letterSpacing; - } - } else { - // LTR case is easier, we just add to the advance. - shaping.m_advance[i] += m_letterSpacing; - shaping.m_abc.abcB += m_letterSpacing; - } - } - } - } - - // Go through all the characters to find whitespace and insert the - // extra wordspacing amount for the glyphs they correspond to. - if (m_wordSpacing != 0) { - for (int i = 0; i < shaping.charLength(); i++) { - if (!TreatAsSpace(m_input[m_runs[run].iCharPos + i])) - continue; - - // The char in question is a word separator... - int glyphIndex = shaping.m_logs[i]; - - // Spaces will not have a glyph in Uniscribe, it will just add - // additional advance to the character to the left of the - // space. The space's corresponding glyph will be the character - // following it in reading order. - if (isRtl) { - // In RTL, the glyph to the left of the space is the same - // as the first glyph of the following character, so we can - // just increment it. - shaping.m_advance[glyphIndex] += m_wordSpacing; - shaping.m_abc.abcB += m_wordSpacing; - } else { - // LTR is actually more complex here, we apply it to the - // previous character if there is one, otherwise we have to - // apply it to the leading space of the run. - if (glyphIndex == 0) { - shaping.m_prePadding += m_wordSpacing; - } else { - shaping.m_advance[glyphIndex - 1] += m_wordSpacing; - shaping.m_abc.abcB += m_wordSpacing; - } - } - } - } // m_wordSpacing != 0 - - // Loop for next run... - } -} - -// The advance is the ABC width of the run -int UniscribeHelper::AdvanceForItem(int item_index) const -{ - int accum = 0; - const Shaping& shaping = m_shapes[item_index]; - - if (shaping.m_justify.size() == 0) { - // Easy case with no justification, the width is just the ABC width of - // the run. (The ABC width is the sum of the advances). - return shaping.m_abc.abcA + shaping.m_abc.abcB + - shaping.m_abc.abcC + shaping.m_prePadding; - } - - // With justification, we use the justified amounts instead. The - // justification array contains both the advance and the extra space - // added for justification, so is the width we want. - int justification = 0; - for (size_t i = 0; i < shaping.m_justify.size(); i++) - justification += shaping.m_justify[i]; - - return shaping.m_prePadding + justification; -} - -} // namespace WebCore diff --git a/webkit/port/platform/graphics/chromium/UniscribeHelper.h b/webkit/port/platform/graphics/chromium/UniscribeHelper.h deleted file mode 100644 index 1079e74..0000000 --- a/webkit/port/platform/graphics/chromium/UniscribeHelper.h +++ /dev/null @@ -1,404 +0,0 @@ -// Copyright (c) 2006-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. - -// A wrapper around Uniscribe that provides a reasonable API. - -#ifndef UniscribeHelper_h -#define UniscribeHelper_h - -#include <windows.h> -#include <usp10.h> -#include <map> - -#include <unicode/uchar.h> -#include <wtf/Vector.h> - -class UniscribeTest_TooBig_Test; // A gunit test for UniscribeHelper. - -namespace WebCore { - -#define UNISCRIBE_HELPER_STACK_RUNS 8 -#define UNISCRIBE_HELPER_STACK_CHARS 32 - -// This object should be safe to create & destroy frequently, as long as the -// caller preserves the script_cache when possible (this data may be slow to -// compute). -// -// This object is "kind of large" (~1K) because it reserves a lot of space for -// working with to avoid expensive heap operations. Therefore, not only should -// you not worry about creating and destroying it, you should try to not keep -// them around. -class UniscribeHelper { -public: - // Initializes this Uniscribe run with the text pointed to by |run| with - // |length|. The input is NOT null terminated. - // - // The is_rtl flag should be set if the input script is RTL. It is assumed - // that the caller has already divided up the input text (using ICU, for - // example) into runs of the same direction of script. This avoids - // disagreements between the caller and Uniscribe later (see FillItems). - // - // A script cache should be provided by the caller that is initialized to - // NULL. When the caller is done with the cache (it may be stored between - // runs as long as it is used consistently with the same HFONT), it should - // call ScriptFreeCache(). - UniscribeHelper(const UChar* input, - int inputLength, - bool isRtl, - HFONT hfont, - SCRIPT_CACHE* scriptCache, - SCRIPT_FONTPROPERTIES* fontProperties); - - virtual ~UniscribeHelper(); - - // Sets Uniscribe's directional override flag. False by default. - bool directionalOverride() const - { - return m_directionalOverride; - } - void setDirectionalOverride(bool override) - { - m_directionalOverride = override; - } - - // Set's Uniscribe's no-ligate override flag. False by default. - bool inhibitLigate() const - { - return m_inhibitLigate; - } - void setInhibitLigate(bool inhibit) - { - m_inhibitLigate = inhibit; - } - - // Set letter spacing. We will try to insert this much space between - // graphemes (one or more glyphs perceived as a single unit by ordinary - // users of a script). Positive values increase letter spacing, negative - // values decrease it. 0 by default. - int letterSpacing() const - { - return m_letterSpacing; - } - void setLetterSpacing(int letterSpacing) - { - m_letterSpacing = letterSpacing; - } - - // Set the width of a standard space character. We use this to normalize - // space widths. Windows will make spaces after Hindi characters larger than - // other spaces. A space_width of 0 means to use the default space width. - // - // Must be set before Init() is called. - int spaceWidth() const - { - return m_spaceWidth; - } - void setSpaceWidth(int spaceWidth) - { - m_spaceWidth = spaceWidth; - } - - // Set word spacing. We will try to insert this much extra space between - // each word in the input (beyond whatever whitespace character separates - // words). Positive values lead to increased letter spacing, negative values - // decrease it. 0 by default. - // - // Must be set before Init() is called. - int wordSpacing() const - { - return m_wordSpacing; - } - void setWordSpacing(int wordSpacing) - { - m_wordSpacing = wordSpacing; - } - - void setAscent(int ascent) - { - m_ascent = ascent; - } - - // You must call this after setting any options but before doing any - // other calls like asking for widths or drawing. - void Init() - { - InitWithOptionalLengthProtection(true); - } - - // Returns the total width in pixels of the text run. - int Width() const; - - // Call to justify the text, with the amount of space that should be ADDED - // to get the desired width that the column should be justified to. - // Normally, spaces are inserted, but for Arabic there will be kashidas - // (extra strokes) inserted instead. - // - // This function MUST be called AFTER Init(). - void Justify(int additionalSpace); - - // Computes the given character offset into a pixel offset of the beginning - // of that character. - int CharacterToX(int offset) const; - - // Converts the given pixel X position into a logical character offset into - // the run. For positions appearing before the first character, this will - // return -1. - int XToCharacter(int x) const; - - // Draws the given characters to (x, y) in the given DC. The font will be - // handled by this function, but the font color and other attributes should - // be pre-set. - // - // The y position is the upper left corner, NOT the baseline. - void Draw(HDC dc, int x, int y, int from, int to); - - // Returns the first glyph assigned to the character at the given offset. - // This function is used to retrieve glyph information when Uniscribe is - // being used to generate glyphs for non-complex, non-BMP (above U+FFFF) - // characters. These characters are not otherwise special and have no - // complex shaping rules, so we don't otherwise need Uniscribe, except - // Uniscribe is the only way to get glyphs for non-BMP characters. - // - // Returns 0 if there is no glyph for the given character. - WORD FirstGlyphForCharacter(int charOffset) const; - -protected: - // Backend for init. The flag allows the unit test to specify whether we - // should fail early for very long strings like normal, or try to pass the - // long string to Uniscribe. The latter provides a way to force failure of - // shaping. - void InitWithOptionalLengthProtection(bool lengthProtection); - - // Tries to preload the font when the it is not accessible. - // This is the default implementation and it does not do anything. - virtual void TryToPreloadFont(HFONT font) {} - -private: - friend class UniscribeTest_TooBig_Test; - - // An array corresponding to each item in runs_ containing information - // on each of the glyphs that were generated. Like runs_, this is in - // reading order. However, for rtl text, the characters within each - // item will be reversed. - struct Shaping { - Shaping() - : m_prePadding(0) - , m_hfont(NULL) - , m_scriptCache(NULL) - , m_ascentOffset(0) { - m_abc.abcA = 0; - m_abc.abcB = 0; - m_abc.abcC = 0; - } - - // Returns the number of glyphs (which will be drawn to the screen) - // in this run. - int glyphLength() const - { - return static_cast<int>(m_glyphs.size()); - } - - // Returns the number of characters (that we started with) in this run. - int charLength() const - { - return static_cast<int>(m_logs.size()); - } - - // Returns the advance array that should be used when measuring glyphs. - // The returned pointer will indicate an array with glyph_length() - // elements and the advance that should be used for each one. This is - // either the real advance, or the justified advances if there is one, - // and is the array we want to use for measurement. - const int* effectiveAdvances() const - { - if (m_advance.size() == 0) - return 0; - if (m_justify.size() == 0) - return &m_advance[0]; - return &m_justify[0]; - } - - // This is the advance amount of space that we have added to the - // beginning of the run. It is like the ABC's |A| advance but one that - // we create and must handle internally whenever computing with pixel - // offsets. - int m_prePadding; - - // Glyph indices in the font used to display this item. These indices - // are in screen order. - Vector<WORD, UNISCRIBE_HELPER_STACK_CHARS> m_glyphs; - - // For each input character, this tells us the first glyph index it - // generated. This is the only array with size of the input chars. - // - // All offsets are from the beginning of this run. Multiple characters - // can generate one glyph, in which case there will be adjacent - // duplicates in this list. One character can also generate multiple - // glyphs, in which case there will be skipped indices in this list. - Vector<WORD, UNISCRIBE_HELPER_STACK_CHARS> m_logs; - - // Flags and such for each glyph. - Vector<SCRIPT_VISATTR, UNISCRIBE_HELPER_STACK_CHARS> m_visattr; - - // Horizontal advances for each glyph listed above, this is basically - // how wide each glyph is. - Vector<int, UNISCRIBE_HELPER_STACK_CHARS> m_advance; - - // This contains glyph offsets, from the nominal position of a glyph. - // It is used to adjust the positions of multiple combining characters - // around/above/below base characters in a context-sensitive manner so - // that they don't bump against each other and the base character. - Vector<GOFFSET, UNISCRIBE_HELPER_STACK_CHARS> m_offsets; - - // Filled by a call to Justify, this is empty for nonjustified text. - // If nonempty, this contains the array of justify characters for each - // character as returned by ScriptJustify. - // - // This is the same as the advance array, but with extra space added - // for some characters. The difference between a glyph's |justify| - // width and it's |advance| width is the extra space added. - Vector<int, UNISCRIBE_HELPER_STACK_CHARS> m_justify; - - // Sizing information for this run. This treats the entire run as a - // character with a preceeding advance, width, and ending advance. The - // B width is the sum of the |advance| array, and the A and C widths - // are any extra spacing applied to each end. - // - // It is unclear from the documentation what this actually means. From - // experimentation, it seems that the sum of the character advances is - // always the sum of the ABC values, and I'm not sure what you're - // supposed to do with the ABC values. - ABC m_abc; - - // Pointers to windows font data used to render this run. - HFONT m_hfont; - SCRIPT_CACHE* m_scriptCache; - - // Ascent offset between the ascent of the primary font - // and that of the fallback font. The offset needs to be applied, - // when drawing a string, to align multiple runs rendered with - // different fonts. - int m_ascentOffset; - }; - - // Computes the runs_ array from the text run. - void FillRuns(); - - // Computes the shapes_ array given an runs_ array already filled in. - void FillShapes(); - - // Fills in the screen_order_ array (see below). - void FillScreenOrder(); - - // Called to update the glyph positions based on the current spacing - // options that are set. - void ApplySpacing(); - - // Normalizes all advances for spaces to the same width. This keeps windows - // from making spaces after Hindi characters larger, which is then - // inconsistent with our meaure of the width since WebKit doesn't include - // spaces in text-runs sent to uniscribe unless white-space:pre. - void AdjustSpaceAdvances(); - - // Returns the total width of a single item. - int AdvanceForItem(int item_index) const; - - // Shapes a run (pointed to by |input|) using |hfont| first. - // Tries a series of fonts specified retrieved with NextWinFontData - // and finally a font covering characters in |*input|. A string pointed - // by |input| comes from ScriptItemize and is supposed to contain - // characters belonging to a single script aside from characters common to - // all scripts (e.g. space). - bool Shape(const UChar* input, - int item_length, - int num_glyphs, - SCRIPT_ITEM& run, - Shaping& shaping); - - // Gets Windows font data for the next best font to try in the list - // of fonts. When there's no more font available, returns false - // without touching any of out params. Need to call ResetFontIndex - // to start scanning of the font list from the beginning. - virtual bool NextWinFontData(HFONT* hfont, - SCRIPT_CACHE** script_cache, - SCRIPT_FONTPROPERTIES** font_properties, - int* ascent) { - return false; - } - - // Resets the font index to the first in the list of fonts to try after the - // primaryFont turns out not to work. With fontIndex reset, - // NextWinFontData scans fallback fonts from the beginning. - virtual void ResetFontIndex() {} - - // The input data for this run of Uniscribe. See the constructor. - const UChar* m_input; - const int m_inputLength; - const bool m_isRtl; - - // Windows font data for the primary font. In a sense, m_logfont and m_style - // are redundant because m_hfont contains all the information. However, - // invoking GetObject, everytime we need the height and the style, is rather - // expensive so that we cache them. Would it be better to add getter and - // (virtual) setter for the height and the style of the primary font, - // instead of m_logfont? Then, a derived class ctor can set m_ascent, - // m_height and m_style if they're known. Getters for them would have to - // 'infer' their values from m_hfont ONLY when they're not set. - HFONT m_hfont; - SCRIPT_CACHE* m_scriptCache; - SCRIPT_FONTPROPERTIES* m_fontProperties; - int m_ascent; - LOGFONT m_logfont; - int m_style; - - // Options, see the getters/setters above. - bool m_directionalOverride; - bool m_inhibitLigate; - int m_letterSpacing; - int m_spaceWidth; - int m_wordSpacing; - - // Uniscribe breaks the text into Runs. These are one length of text that is - // in one script and one direction. This array is in reading order. - Vector<SCRIPT_ITEM, UNISCRIBE_HELPER_STACK_RUNS> m_runs; - - Vector<Shaping, UNISCRIBE_HELPER_STACK_RUNS> m_shapes; - - // This is a mapping between reading order and screen order for the items. - // Uniscribe's items array are in reading order. For right-to-left text, - // or mixed (although WebKit's |TextRun| should really be only one - // direction), this makes it very difficult to compute character offsets - // and positions. This list is in screen order from left to right, and - // gives the index into the |m_runs| and |m_shapes| arrays of each - // subsequent item. - Vector<int, UNISCRIBE_HELPER_STACK_RUNS> m_screenOrder; -}; - -} // namespace WebCore - -#endif // UniscribeHelper_h diff --git a/webkit/port/platform/graphics/chromium/UniscribeHelperTextRun.cpp b/webkit/port/platform/graphics/chromium/UniscribeHelperTextRun.cpp deleted file mode 100644 index 93d23e9..0000000 --- a/webkit/port/platform/graphics/chromium/UniscribeHelperTextRun.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (C) 2006, 2007 Apple 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: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "UniscribeHelperTextRun.h" - -#include "ChromiumBridge.h" -#include "Font.h" -#include "SimpleFontData.h" - -namespace WebCore { - -UniscribeHelperTextRun::UniscribeHelperTextRun(const WebCore::TextRun& run, - const WebCore::Font& font) - : UniscribeHelper(run.characters(), run.length(), run.rtl(), - font.primaryFont()->platformData().hfont(), - font.primaryFont()->platformData().scriptCache(), - font.primaryFont()->platformData().scriptFontProperties()) - , m_font(&font) - , m_fontIndex(0) -{ - setDirectionalOverride(run.directionalOverride()); - setLetterSpacing(font.letterSpacing()); - setSpaceWidth(font.spaceWidth()); - setWordSpacing(font.wordSpacing()); - setAscent(font.primaryFont()->ascent()); - - Init(); - - // Padding is the amount to add to make justification happen. This - // should be done after Init() so all the runs are already measured. - if (run.padding() > 0) - Justify(run.padding()); -} - -UniscribeHelperTextRun::UniscribeHelperTextRun( - const wchar_t* input, - int inputLength, - bool isRtl, - HFONT hfont, - SCRIPT_CACHE* scriptCache, - SCRIPT_FONTPROPERTIES* fontProperties) - : UniscribeHelper(input, inputLength, isRtl, hfont, - scriptCache, fontProperties) - , m_font(NULL) - , m_fontIndex(-1) -{ -} - -void UniscribeHelperTextRun::TryToPreloadFont(HFONT font) -{ - // Ask the browser to get the font metrics for this font. - // That will preload the font and it should now be accessible - // from the renderer. - WebCore::ChromiumBridge::ensureFontLoaded(font); -} - -bool UniscribeHelperTextRun::NextWinFontData( - HFONT* hfont, - SCRIPT_CACHE** scriptCache, - SCRIPT_FONTPROPERTIES** fontProperties, - int* ascent) -{ - // This check is necessary because NextWinFontData can be called again - // after we already ran out of fonts. fontDataAt behaves in a strange - // manner when the difference between param passed and # of fonts stored in - // WebKit::Font is larger than one. We can avoid this check by setting - // font_index_ to # of elements in hfonts_ when we run out of font. In that - // case, we'd have to go through a couple of more checks before returning - // false. - if (m_fontIndex == -1 || !m_font) - return false; - - // If the font data for a fallback font requested is not yet retrieved, add - // them to our vectors. Note that '>' rather than '>=' is used to test that - // condition. primaryFont is not stored in hfonts_, and friends so that - // indices for fontDataAt and our vectors for font data are 1 off from each - // other. That is, when fully populated, hfonts_ and friends have one font - // fewer than what's contained in font_. - if (static_cast<size_t>(++m_fontIndex) > m_hfonts.size()) { - const WebCore::FontData *fontData = m_font->fontDataAt(m_fontIndex); - if (!fontData) { - // Ran out of fonts. - m_fontIndex = -1; - return false; - } - - // TODO(ericroman): this won't work for SegmentedFontData - // http://b/issue?id=1007335 - const WebCore::SimpleFontData* simpleFontData = - fontData->fontDataForCharacter(' '); - - m_hfonts.append(simpleFontData->platformData().hfont()); - m_scriptCaches.append( - simpleFontData->platformData().scriptCache()); - m_fontProperties.append( - simpleFontData->platformData().scriptFontProperties()); - m_ascents.append(simpleFontData->ascent()); - } - - *hfont = m_hfonts[m_fontIndex - 1]; - *scriptCache = m_scriptCaches[m_fontIndex - 1]; - *fontProperties = m_fontProperties[m_fontIndex - 1]; - *ascent = m_ascents[m_fontIndex - 1]; - return true; -} - -void UniscribeHelperTextRun::ResetFontIndex() -{ - m_fontIndex = 0; -} - -} // namespace WebCore diff --git a/webkit/port/platform/graphics/chromium/UniscribeHelperTextRun.h b/webkit/port/platform/graphics/chromium/UniscribeHelperTextRun.h deleted file mode 100644 index 281e6d9..0000000 --- a/webkit/port/platform/graphics/chromium/UniscribeHelperTextRun.h +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -/* - * Copyright (C) 2006, 2007 Apple 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: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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. - */ - -#ifndef UniscribeHelperTextRun_h -#define UniscribeHelperTextRun_h - -#include "UniscribeHelper.h" - -namespace WebCore { - -class Font; -class TextRun; - -// Wrapper around the Uniscribe helper that automatically sets it up with the -// WebKit types we supply. -class UniscribeHelperTextRun : public UniscribeHelper { -public: - // Regular constructor used for WebCore text run processing. - UniscribeHelperTextRun(const WebCore::TextRun& run, - const WebCore::Font& font); - - // Constructor with the same interface as the gfx::UniscribeState. Using - // this constructor will not give you font fallback, but it will provide - // the ability to load fonts that may not be in the OS cache - // ("TryToPreloadFont") if the caller does not have a TextRun/Font. - UniscribeHelperTextRun(const wchar_t* input, - int inputLength, - bool isRtl, - HFONT hfont, - SCRIPT_CACHE* scriptCache, - SCRIPT_FONTPROPERTIES* fontProperties); - -protected: - virtual void TryToPreloadFont(HFONT font); - -private: - // This function retrieves the Windows font data (HFONT, etc) for the next - // WebKit font in the list. If the font data corresponding to font_index_ - // has been obtained before, returns the values stored in our internal - // vectors (hfonts_, etc). Otherwise, it gets next SimpleFontData from - // WebKit and adds them to in hfonts_ and friends so that font data can be - // returned quickly next time they're requested. - virtual bool NextWinFontData(HFONT* hfont, - SCRIPT_CACHE** scriptCache, - SCRIPT_FONTPROPERTIES** fontProperties, - int* ascent); - virtual void ResetFontIndex(); - - // Reference to WebKit::Font that contains all the information about fonts - // we can use to render this input run of text. It is used in - // NextWinFontData to retrieve Windows font data for a series of - // non-primary fonts. - // - // This pointer can be NULL for no font fallback handling. - const Font* m_font; - - // It's rare that many fonts are listed in stylesheets. - // Four would be large enough in most cases. - const static size_t kNumberOfFonts = 4; - - // These vectors are used to store Windows font data for non-primary fonts. - Vector<HFONT, kNumberOfFonts> m_hfonts; - Vector<SCRIPT_CACHE*, kNumberOfFonts> m_scriptCaches; - Vector<SCRIPT_FONTPROPERTIES*, kNumberOfFonts> m_fontProperties; - Vector<int, kNumberOfFonts> m_ascents; - - // Index of the fallback font we're currently using for NextWinFontData. - int m_fontIndex; -}; - -} // namespace WebCore - -#endif // UniscribeHelperTextRun_h |