Remove FontTranscoder
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Sep 2013 16:21:54 +0000 (16:21 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Sep 2013 16:21:54 +0000 (16:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=122088

Reviewed by Andreas Kling.

This overly generic class just implements mapping of backslash to yen symbol for some legacy Japanese fonts.

* CMakeLists.txt:
* GNUmakefile.am:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.pri:
* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.xcodeproj/project.pbxproj:
* platform/graphics/Font.cpp:
(WebCore::useBackslashAsYenSignForFamily):

    Move the family set to Font.cpp.

(WebCore::Font::Font):
(WebCore::Font::operator=):
(WebCore::Font::update):

    Keep the cached boolean up to date.

* platform/graphics/Font.h:
(WebCore::Font::useBackslashAsYenSymbol):

    Use descriptive name instead of talking about "transcoding".

* platform/text/transcoder: Removed.
* platform/text/transcoder/FontTranscoder.cpp: Removed.
* platform/text/transcoder/FontTranscoder.h: Removed.
* rendering/RenderText.cpp:
(WebCore::RenderText::RenderText):
(WebCore::RenderText::computeUseBackslashAsYenSymbol):

    Rename for clarity.
    Avoid unnecessary hash lookup, just check the cached bit in Font.

(WebCore::RenderText::styleDidChange):
(WebCore::RenderText::setTextInternal):

    "Transcoding" here was just a simple character replacement.

(WebCore::RenderText::textWithoutConvertingBackslashToYenSymbol):

    Renamed.

* rendering/RenderText.h:

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

16 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.am
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Target.pri
Source/WebCore/WebCore.pri
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/accessibility/AccessibilityRenderObject.cpp
Source/WebCore/editing/TextIterator.cpp
Source/WebCore/platform/graphics/Font.cpp
Source/WebCore/platform/graphics/Font.h
Source/WebCore/platform/text/transcoder/FontTranscoder.cpp [deleted file]
Source/WebCore/platform/text/transcoder/FontTranscoder.h [deleted file]
Source/WebCore/rendering/RenderText.cpp
Source/WebCore/rendering/RenderText.h

index ba79281..72d889d 100644 (file)
@@ -74,7 +74,6 @@ set(WebCore_INCLUDE_DIRECTORIES
     "${WEBCORE_DIR}/platform/network"
     "${WEBCORE_DIR}/platform/sql"
     "${WEBCORE_DIR}/platform/text"
-    "${WEBCORE_DIR}/platform/text/transcoder"
     "${WEBCORE_DIR}/plugins"
     "${WEBCORE_DIR}/rendering"
     "${WEBCORE_DIR}/rendering/mathml"
@@ -2095,8 +2094,6 @@ set(WebCore_SOURCES
     platform/text/TextStream.cpp
     platform/text/UnicodeRange.cpp
 
-    platform/text/transcoder/FontTranscoder.cpp
-
     plugins/DOMMimeType.cpp
     plugins/DOMMimeTypeArray.cpp
     plugins/DOMPlugin.cpp
index e9f4b2c..4f68c04 100644 (file)
@@ -1,3 +1,56 @@
+2013-09-30  Antti Koivisto  <antti@apple.com>
+
+        Remove FontTranscoder
+        https://bugs.webkit.org/show_bug.cgi?id=122088
+
+        Reviewed by Andreas Kling.
+
+        This overly generic class just implements mapping of backslash to yen symbol for some legacy Japanese fonts.
+
+        * CMakeLists.txt:
+        * GNUmakefile.am:
+        * GNUmakefile.list.am:
+        * Target.pri:
+        * WebCore.pri:
+        * WebCore.vcxproj/WebCore.vcxproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/graphics/Font.cpp:
+        (WebCore::useBackslashAsYenSignForFamily):
+        
+            Move the family set to Font.cpp.
+
+        (WebCore::Font::Font):
+        (WebCore::Font::operator=):
+        (WebCore::Font::update):
+        
+            Keep the cached boolean up to date.
+
+        * platform/graphics/Font.h:
+        (WebCore::Font::useBackslashAsYenSymbol):
+        
+            Use descriptive name instead of talking about "transcoding".
+
+        * platform/text/transcoder: Removed.
+        * platform/text/transcoder/FontTranscoder.cpp: Removed.
+        * platform/text/transcoder/FontTranscoder.h: Removed.
+        * rendering/RenderText.cpp:
+        (WebCore::RenderText::RenderText):
+        (WebCore::RenderText::computeUseBackslashAsYenSymbol):
+        
+            Rename for clarity. 
+            Avoid unnecessary hash lookup, just check the cached bit in Font.
+
+        (WebCore::RenderText::styleDidChange):
+        (WebCore::RenderText::setTextInternal):
+        
+            "Transcoding" here was just a simple character replacement.
+
+        (WebCore::RenderText::textWithoutConvertingBackslashToYenSymbol):
+        
+            Renamed.
+
+        * rendering/RenderText.h:
+
 2013-09-27  Jer Noble  <jer.noble@apple.com>
 
         REGRESSION(r156546): media/video-no-audio.html broken
index 9c20ddf..3fb92ef 100644 (file)
@@ -86,7 +86,6 @@ webcore_cppflags += \
        -I$(srcdir)/Source/WebCore/platform/network/gtk \
        -I$(srcdir)/Source/WebCore/platform/sql \
        -I$(srcdir)/Source/WebCore/platform/text \
-       -I$(srcdir)/Source/WebCore/platform/text/transcoder \
        -I$(srcdir)/Source/WebCore/platform/win \
        -I$(srcdir)/Source/WebCore/plugins \
        -I$(srcdir)/Source/WebCore/plugins/win \
index 61dc9aa..f71a560 100644 (file)
@@ -5957,8 +5957,6 @@ platform_sources += \
        Source/WebCore/platform/network/ProxyServer.h \
        Source/WebCore/platform/text/enchant/TextCheckerEnchant.h \
        Source/WebCore/platform/text/enchant/TextCheckerEnchant.cpp \
-       Source/WebCore/platform/text/transcoder/FontTranscoder.cpp \
-       Source/WebCore/platform/text/transcoder/FontTranscoder.h \
        Source/WebCore/platform/text/BidiContext.cpp \
        Source/WebCore/platform/text/BidiContext.h \
        Source/WebCore/platform/text/BidiResolver.h \
index 36f3b20..1f4cf6a 100644 (file)
@@ -1103,7 +1103,6 @@ SOURCES += \
     platform/ThreadTimers.cpp \
     platform/Timer.cpp \
     platform/text/UnicodeRange.cpp \
-    platform/text/transcoder/FontTranscoder.cpp \
     platform/UUID.cpp \
     platform/Widget.cpp \
     platform/PlatformStrategies.cpp \
@@ -2342,7 +2341,6 @@ HEADERS += \
     platform/text/TextEncodingRegistry.h \
     platform/text/TextStream.h \
     platform/text/UnicodeRange.h \
-    platform/text/transcoder/FontTranscoder.h \
     platform/ThreadGlobalData.h \
     platform/ThreadTimers.h \
     platform/Timer.h \
index 7af60e9..b44c3fa 100644 (file)
@@ -81,7 +81,6 @@ INCLUDEPATH += \
     $$SOURCE_DIR/platform/qt \
     $$SOURCE_DIR/platform/sql \
     $$SOURCE_DIR/platform/text \
-    $$SOURCE_DIR/platform/text/transcoder \
     $$SOURCE_DIR/plugins \
     $$SOURCE_DIR/rendering \
     $$SOURCE_DIR/rendering/mathml \
index c55a2c4..1157488 100644 (file)
     <ClCompile Include="..\platform\text\cf\StringCF.cpp" />
     <ClCompile Include="..\platform\text\cf\StringImplCF.cpp" />
     <ClCompile Include="..\platform\text\win\TextBreakIteratorInternalICUWin.cpp" />
-    <ClCompile Include="..\platform\text\transcoder\FontTranscoder.cpp" />
     <ClCompile Include="..\platform\image-decoders\ImageDecoder.cpp">
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
     <ClInclude Include="..\platform\graphics\WidthCache.h" />
     <ClInclude Include="..\platform\graphics\WidthIterator.h" />
     <ClInclude Include="..\platform\text\WritingMode.h" />
-    <ClInclude Include="..\platform\text\transcoder\FontTranscoder.h" />
     <ClInclude Include="..\platform\image-decoders\ImageDecoder.h">
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
index bac6842..f6415ce 100644 (file)
                B6D9D27B14EAC0860090D75E /* JSFocusEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = B6D9D27914EAC0860090D75E /* JSFocusEvent.h */; };
                B6D9D27C14EAC0860090D75E /* JSFocusEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B6D9D27A14EAC0860090D75E /* JSFocusEvent.cpp */; };
                B71FE6DF11091CB300DAEF77 /* PrintContext.h in Headers */ = {isa = PBXBuildFile; fileRef = B776D43A1104525D00BEB0EC /* PrintContext.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               B734B181119B9911006587BD /* FontTranscoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B734B180119B9911006587BD /* FontTranscoder.cpp */; };
-               B734B183119B991D006587BD /* FontTranscoder.h in Headers */ = {isa = PBXBuildFile; fileRef = B734B182119B991D006587BD /* FontTranscoder.h */; };
                B776D43D1104527500BEB0EC /* PrintContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B776D43C1104527500BEB0EC /* PrintContext.cpp */; };
                B885E8D411E06DD2009FFBF4 /* InspectorApplicationCacheAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B885E8D211E06DD2009FFBF4 /* InspectorApplicationCacheAgent.cpp */; };
                B885E8D511E06DD2009FFBF4 /* InspectorApplicationCacheAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = B885E8D311E06DD2009FFBF4 /* InspectorApplicationCacheAgent.h */; settings = {ATTRIBUTES = (); }; };
                B6D9D27214EABF030090D75E /* FocusEvent.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = FocusEvent.idl; sourceTree = "<group>"; };
                B6D9D27914EAC0860090D75E /* JSFocusEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSFocusEvent.h; sourceTree = "<group>"; };
                B6D9D27A14EAC0860090D75E /* JSFocusEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSFocusEvent.cpp; sourceTree = "<group>"; };
-               B734B180119B9911006587BD /* FontTranscoder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FontTranscoder.cpp; path = transcoder/FontTranscoder.cpp; sourceTree = "<group>"; };
-               B734B182119B991D006587BD /* FontTranscoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FontTranscoder.h; path = transcoder/FontTranscoder.h; sourceTree = "<group>"; };
                B776D43A1104525D00BEB0EC /* PrintContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrintContext.h; sourceTree = "<group>"; };
                B776D43C1104527500BEB0EC /* PrintContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PrintContext.cpp; sourceTree = "<group>"; };
                B885E8D211E06DD2009FFBF4 /* InspectorApplicationCacheAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorApplicationCacheAgent.cpp; sourceTree = "<group>"; };
                        children = (
                                B2B264590D00A77E000ACC1D /* cf */,
                                B2C3D9F90D006C1D00EF6F26 /* mac */,
-                               B734B17F119B98DB006587BD /* transcoder */,
                                37C61F0012095C87007A3C67 /* AtomicStringKeyedMRUCache.h */,
                                B2C3D9F20D006C1D00EF6F26 /* BidiContext.cpp */,
                                B2C3D9F30D006C1D00EF6F26 /* BidiContext.h */,
                        name = generic;
                        sourceTree = "<group>";
                };
-               B734B17F119B98DB006587BD /* transcoder */ = {
-                       isa = PBXGroup;
-                       children = (
-                               B734B180119B9911006587BD /* FontTranscoder.cpp */,
-                               B734B182119B991D006587BD /* FontTranscoder.h */,
-                       );
-                       name = transcoder;
-                       sourceTree = "<group>";
-               };
                BC1A3790097C6F970019F3D8 /* bindings */ = {
                        isa = PBXGroup;
                        children = (
                                B2C3DA6B0D006CD600EF6F26 /* FontSelector.h in Headers */,
                                37202199106213C600F25C4B /* FontSmoothingMode.h in Headers */,
                                3784C34B0E11AA34007D8D48 /* FontTraitsMask.h in Headers */,
-                               B734B183119B991D006587BD /* FontTranscoder.h in Headers */,
                                A80E6CED0A1989CA007FB8C5 /* FontValue.h in Headers */,
                                BCE4413612F7490B009B84B8 /* FontWidthVariant.h in Headers */,
                                4A0DA2FF129B241900AB61E1 /* FormAssociatedElement.h in Headers */,
                                B2AFFC800D00A5C10030074D /* FontMac.mm in Sources */,
                                84B62685133138F90095A489 /* FontPlatformData.cpp in Sources */,
                                B5320D6C122A24E9002D1440 /* FontPlatformDataCocoa.mm in Sources */,
-                               B734B181119B9911006587BD /* FontTranscoder.cpp in Sources */,
                                A80E6CF10A1989CA007FB8C5 /* FontValue.cpp in Sources */,
                                4A0DA2FE129B241900AB61E1 /* FormAssociatedElement.cpp in Sources */,
                                D05CED290A40BB2C00C5AF38 /* FormatBlockCommand.cpp in Sources */,
index 8af3e2f..9ea79a1 100644 (file)
@@ -3372,7 +3372,7 @@ String AccessibilityRenderObject::passwordFieldValue() const
         return String();
 
     // Return the text that is actually being rendered in the input field.
-    return static_cast<RenderText*>(renderer)->textWithoutTranscoding();
+    return static_cast<RenderText*>(renderer)->textWithoutConvertingBackslashToYenSymbol();
 #else
     // It seems only GTK is interested in this at the moment.
     return String();
index e1e4d8c..af38768 100644 (file)
@@ -1032,7 +1032,7 @@ void TextIterator::emitCharacter(UChar c, Node* textNode, Node* offsetBaseNode,
 void TextIterator::emitText(Node* textNode, RenderObject* renderObject, int textStartOffset, int textEndOffset)
 {
     RenderText* renderer = toRenderText(renderObject);
-    m_text = m_emitsOriginalText ? renderer->originalText() : (m_emitsTextWithoutTranscoding ? renderer->textWithoutTranscoding() : renderer->text());
+    m_text = m_emitsOriginalText ? renderer->originalText() : (m_emitsTextWithoutTranscoding ? renderer->textWithoutConvertingBackslashToYenSymbol() : renderer->text());
     ASSERT(!m_text.isEmpty());
     ASSERT(0 <= textStartOffset && textStartOffset < static_cast<int>(m_text.length()));
     ASSERT(0 <= textEndOffset && textEndOffset <= static_cast<int>(m_text.length()));
index f8a9bd4..f826d55 100644 (file)
 
 #include "FloatRect.h"
 #include "FontCache.h"
-#include "FontTranscoder.h"
 #include "IntPoint.h"
 #include "GlyphBuffer.h"
 #include "TextRun.h"
 #include "WidthIterator.h"
 #include <wtf/MainThread.h>
 #include <wtf/MathExtras.h>
+#include <wtf/text/AtomicStringHash.h>
 #include <wtf/text/StringBuilder.h>
 
 using namespace WTF;
@@ -61,6 +61,36 @@ const uint8_t Font::s_roundingHackCharacterTable[256] = {
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
 };
 
+static bool useBackslashAsYenSignForFamily(const AtomicString& family)
+{
+    if (family.isEmpty())
+        return false;
+    static HashSet<AtomicString>* set;
+    if (!set) {
+        set = new HashSet<AtomicString>;
+        set->add("MS PGothic");
+        UChar unicodeNameMSPGothic[] = {0xFF2D, 0xFF33, 0x0020, 0xFF30, 0x30B4, 0x30B7, 0x30C3, 0x30AF};
+        set->add(AtomicString(unicodeNameMSPGothic, WTF_ARRAY_LENGTH(unicodeNameMSPGothic)));
+
+        set->add("MS PMincho");
+        UChar unicodeNameMSPMincho[] = {0xFF2D, 0xFF33, 0x0020, 0xFF30, 0x660E, 0x671D};
+        set->add(AtomicString(unicodeNameMSPMincho, WTF_ARRAY_LENGTH(unicodeNameMSPMincho)));
+
+        set->add("MS Gothic");
+        UChar unicodeNameMSGothic[] = {0xFF2D, 0xFF33, 0x0020, 0x30B4, 0x30B7, 0x30C3, 0x30AF};
+        set->add(AtomicString(unicodeNameMSGothic, WTF_ARRAY_LENGTH(unicodeNameMSGothic)));
+
+        set->add("MS Mincho");
+        UChar unicodeNameMSMincho[] = {0xFF2D, 0xFF33, 0x0020, 0x660E, 0x671D};
+        set->add(AtomicString(unicodeNameMSMincho, WTF_ARRAY_LENGTH(unicodeNameMSMincho)));
+
+        set->add("Meiryo");
+        UChar unicodeNameMeiryo[] = {0x30E1, 0x30A4, 0x30EA, 0x30AA};
+        set->add(AtomicString(unicodeNameMeiryo, WTF_ARRAY_LENGTH(unicodeNameMeiryo)));
+    }
+    return set->contains(family);
+}
+
 Font::CodePath Font::s_codePath = Auto;
 
 TypesettingFeatures Font::s_defaultTypesettingFeatures = 0;
@@ -72,7 +102,7 @@ TypesettingFeatures Font::s_defaultTypesettingFeatures = 0;
 Font::Font()
     : m_letterSpacing(0)
     , m_wordSpacing(0)
-    , m_needsTranscoding(false)
+    , m_useBackslashAsYenSymbol(false)
     , m_typesettingFeatures(0)
 {
 }
@@ -81,7 +111,7 @@ Font::Font(const FontDescription& fd, short letterSpacing, short wordSpacing)
     : m_fontDescription(fd)
     , m_letterSpacing(letterSpacing)
     , m_wordSpacing(wordSpacing)
-    , m_needsTranscoding(fontTranscoder().needsTranscoding(fd))
+    , m_useBackslashAsYenSymbol(useBackslashAsYenSignForFamily(fd.firstFamily()))
     , m_typesettingFeatures(computeTypesettingFeatures())
 {
 }
@@ -90,11 +120,11 @@ Font::Font(const FontPlatformData& fontData, bool isPrinterFont, FontSmoothingMo
     : m_glyphs(FontGlyphs::createForPlatformFont(fontData))
     , m_letterSpacing(0)
     , m_wordSpacing(0)
+    , m_useBackslashAsYenSymbol(false)
     , m_typesettingFeatures(computeTypesettingFeatures())
 {
     m_fontDescription.setUsePrinterFont(isPrinterFont);
     m_fontDescription.setFontSmoothing(fontSmoothingMode);
-    m_needsTranscoding = fontTranscoder().needsTranscoding(fontDescription());
 }
 
 Font::Font(const Font& other)
@@ -102,7 +132,7 @@ Font::Font(const Font& other)
     , m_glyphs(other.m_glyphs)
     , m_letterSpacing(other.m_letterSpacing)
     , m_wordSpacing(other.m_wordSpacing)
-    , m_needsTranscoding(other.m_needsTranscoding)
+    , m_useBackslashAsYenSymbol(other.m_useBackslashAsYenSymbol)
     , m_typesettingFeatures(computeTypesettingFeatures())
 {
 }
@@ -113,7 +143,7 @@ Font& Font::operator=(const Font& other)
     m_glyphs = other.m_glyphs;
     m_letterSpacing = other.m_letterSpacing;
     m_wordSpacing = other.m_wordSpacing;
-    m_needsTranscoding = other.m_needsTranscoding;
+    m_useBackslashAsYenSymbol = other.m_useBackslashAsYenSymbol;
     m_typesettingFeatures = other.m_typesettingFeatures;
     return *this;
 }
@@ -258,6 +288,7 @@ static PassRefPtr<FontGlyphs> retrieveOrAddCachedFontGlyphs(const FontDescriptio
 void Font::update(PassRefPtr<FontSelector> fontSelector) const
 {
     m_glyphs = retrieveOrAddCachedFontGlyphs(m_fontDescription, fontSelector.get());
+    m_useBackslashAsYenSymbol = useBackslashAsYenSignForFamily(firstFamily());
     m_typesettingFeatures = computeTypesettingFeatures();
 }
 
index 98041f0..bd8dbff 100644 (file)
@@ -257,7 +257,7 @@ public:
     static String normalizeSpaces(const LChar*, unsigned length);
     static String normalizeSpaces(const UChar*, unsigned length);
 
-    bool needsTranscoding() const { return m_needsTranscoding; }
+    bool useBackslashAsYenSymbol() const { return m_useBackslashAsYenSymbol; }
     FontGlyphs* glyphs() const { return m_glyphs.get(); }
 
 private:
@@ -318,7 +318,7 @@ private:
     mutable RefPtr<FontGlyphs> m_glyphs;
     short m_letterSpacing;
     short m_wordSpacing;
-    bool m_needsTranscoding;
+    mutable bool m_useBackslashAsYenSymbol;
     mutable unsigned m_typesettingFeatures : 2; // (TypesettingFeatures) Caches values computed from m_fontDescription.
 };
 
diff --git a/Source/WebCore/platform/text/transcoder/FontTranscoder.cpp b/Source/WebCore/platform/text/transcoder/FontTranscoder.cpp
deleted file mode 100644 (file)
index 39ab5e2..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (c) 2010, 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 "FontTranscoder.h"
-
-#include "FontDescription.h"
-#include "TextEncoding.h"
-#include <wtf/unicode/CharacterNames.h>
-
-namespace WebCore {
-
-FontTranscoder::FontTranscoder()
-{
-    m_converterTypes.add("MS PGothic", BackslashToYenSign);
-    UChar unicodeNameMSPGothic[] = {0xFF2D, 0xFF33, 0x0020, 0xFF30, 0x30B4, 0x30B7, 0x30C3, 0x30AF};
-    m_converterTypes.add(AtomicString(unicodeNameMSPGothic, WTF_ARRAY_LENGTH(unicodeNameMSPGothic)), BackslashToYenSign);
-
-    m_converterTypes.add("MS PMincho", BackslashToYenSign);
-    UChar unicodeNameMSPMincho[] = {0xFF2D, 0xFF33, 0x0020, 0xFF30, 0x660E, 0x671D};
-    m_converterTypes.add(AtomicString(unicodeNameMSPMincho, WTF_ARRAY_LENGTH(unicodeNameMSPMincho)), BackslashToYenSign);
-
-    m_converterTypes.add("MS Gothic", BackslashToYenSign);
-    UChar unicodeNameMSGothic[] = {0xFF2D, 0xFF33, 0x0020, 0x30B4, 0x30B7, 0x30C3, 0x30AF};
-    m_converterTypes.add(AtomicString(unicodeNameMSGothic, WTF_ARRAY_LENGTH(unicodeNameMSGothic)), BackslashToYenSign);
-
-    m_converterTypes.add("MS Mincho", BackslashToYenSign);
-    UChar unicodeNameMSMincho[] = {0xFF2D, 0xFF33, 0x0020, 0x660E, 0x671D};
-    m_converterTypes.add(AtomicString(unicodeNameMSMincho, WTF_ARRAY_LENGTH(unicodeNameMSMincho)), BackslashToYenSign);
-
-    m_converterTypes.add("Meiryo", BackslashToYenSign);
-    UChar unicodeNameMeiryo[] = {0x30E1, 0x30A4, 0x30EA, 0x30AA};
-    m_converterTypes.add(AtomicString(unicodeNameMeiryo, WTF_ARRAY_LENGTH(unicodeNameMeiryo)), BackslashToYenSign);
-}
-
-FontTranscoder::ConverterType FontTranscoder::converterType(const FontDescription& fontDescription, const TextEncoding* encoding) const
-{
-    const AtomicString& fontFamily = fontDescription.firstFamily();
-    if (!fontFamily.isNull()) {
-        HashMap<AtomicString, ConverterType>::const_iterator found = m_converterTypes.find(fontFamily);
-        if (found != m_converterTypes.end())
-            return found->value;
-    }
-
-    // IE's default fonts for Japanese encodings change backslashes into yen signs.
-    // We emulate this behavior only when no font is explicitly specified.
-    if (encoding && encoding->backslashAsCurrencySymbol() != '\\' && !fontDescription.isSpecifiedFont())
-        return BackslashToYenSign;
-
-    return NoConversion;
-}
-
-void FontTranscoder::convert(String& text, const FontDescription& fontDescription, const TextEncoding* encoding) const
-{
-    switch (converterType(fontDescription, encoding)) {
-    case BackslashToYenSign: {
-        // FIXME: TextEncoding.h has similar code. We need to factor them out.
-        text.replace('\\', yenSign);
-        break;
-    }
-    case NoConversion:
-    default:
-        ASSERT_NOT_REACHED();
-    }
-}
-
-bool FontTranscoder::needsTranscoding(const FontDescription& fontDescription, const TextEncoding* encoding) const
-{
-    ConverterType type = converterType(fontDescription, encoding);
-    return type != NoConversion;
-}
-
-FontTranscoder& fontTranscoder()
-{
-    static FontTranscoder* transcoder = new FontTranscoder;
-    return *transcoder;
-}
-
-} // namespace WebCore
diff --git a/Source/WebCore/platform/text/transcoder/FontTranscoder.h b/Source/WebCore/platform/text/transcoder/FontTranscoder.h
deleted file mode 100644 (file)
index 6990a10..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 2010, 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 FontTranscoder_h
-#define FontTranscoder_h
-
-#include <wtf/HashMap.h>
-#include <wtf/Noncopyable.h>
-#include <wtf/text/AtomicStringHash.h>
-
-namespace WebCore {
-
-class FontDescription;
-class TextEncoding;
-
-class FontTranscoder {
-    WTF_MAKE_NONCOPYABLE(FontTranscoder); WTF_MAKE_FAST_ALLOCATED;
-public:
-    void convert(String& text, const FontDescription&, const TextEncoding* = 0) const;
-    bool needsTranscoding(const FontDescription&, const TextEncoding* = 0) const;
-
-private:
-    FontTranscoder();
-    ~FontTranscoder(); // Not implemented to make sure nobody accidentally calls delete -- WebCore does not delete singletons.
-
-    enum ConverterType {
-        NoConversion, BackslashToYenSign,
-    };
-
-    ConverterType converterType(const FontDescription&, const TextEncoding*) const;
-
-    HashMap<AtomicString, ConverterType> m_converterTypes;
-
-    friend FontTranscoder& fontTranscoder();
-};
-
-FontTranscoder& fontTranscoder();
-
-} // namespace WebCore
-
-#endif // FontTranscoder_h
index 2f1796e..a8c5eae 100644 (file)
@@ -28,7 +28,6 @@
 #include "AXObjectCache.h"
 #include "EllipsisBox.h"
 #include "FloatQuad.h"
-#include "FontTranscoder.h"
 #include "Frame.h"
 #include "FrameView.h"
 #include "Hyphenation.h"
@@ -145,7 +144,7 @@ RenderText::RenderText(Text* textNode, const String& text)
     , m_containsReversedText(false)
     , m_isAllASCII(text.containsOnlyASCII())
     , m_knownToHaveNoOverflowAndNoFallbackFonts(false)
-    , m_needsTranscoding(false)
+    , m_useBackslashAsYenSymbol(false)
 #if ENABLE(IOS_TEXT_AUTOSIZING)
     , m_candidateComputedTextSize(0)
 #endif
@@ -200,10 +199,17 @@ bool RenderText::isTextFragment() const
     return false;
 }
 
-void RenderText::updateNeedsTranscoding()
+bool RenderText::computeUseBackslashAsYenSymbol() const
 {
+    const FontDescription& fontDescription = style()->font().fontDescription();
+    if (style()->font().useBackslashAsYenSymbol())
+        return true;
+    if (fontDescription.isSpecifiedFont())
+        return false;
     const TextEncoding* encoding = document().decoder() ? &document().decoder()->encoding() : 0;
-    m_needsTranscoding = fontTranscoder().needsTranscoding(style()->font().fontDescription(), encoding);
+    if (encoding && encoding->backslashAsCurrencySymbol() != '\\')
+        return true;
+    return false;
 }
 
 void RenderText::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
@@ -220,10 +226,10 @@ void RenderText::styleDidChange(StyleDifference diff, const RenderStyle* oldStyl
     RenderStyle* newStyle = style();
     bool needsResetText = false;
     if (!oldStyle) {
-        updateNeedsTranscoding();
-        needsResetText = m_needsTranscoding;
-    } else if (oldStyle->font().needsTranscoding() != newStyle->font().needsTranscoding() || (newStyle->font().needsTranscoding() && oldStyle->font().firstFamily() != newStyle->font().firstFamily())) {
-        updateNeedsTranscoding();
+        m_useBackslashAsYenSymbol = computeUseBackslashAsYenSymbol();
+        needsResetText = m_useBackslashAsYenSymbol;
+    } else if (oldStyle->font().useBackslashAsYenSymbol() != newStyle->font().useBackslashAsYenSymbol()) {
+        m_useBackslashAsYenSymbol = computeUseBackslashAsYenSymbol();
         needsResetText = true;
     }
 
@@ -1337,10 +1343,10 @@ void RenderText::setTextInternal(const String& text)
 {
     ASSERT(!text.isNull());
     m_text = text;
-    if (m_needsTranscoding) {
-        const TextEncoding* encoding = document().decoder() ? &document().decoder()->encoding() : 0;
-        fontTranscoder().convert(m_text, style()->font().fontDescription(), encoding);
-    }
+
+    if (m_useBackslashAsYenSymbol)
+        m_text.replace('\\', yenSign);
+
     ASSERT(m_text);
 
     if (style()) {
@@ -1405,14 +1411,11 @@ void RenderText::setText(const String& text, bool force)
         cache->textChanged(this);
 }
 
-String RenderText::textWithoutTranscoding() const
+String RenderText::textWithoutConvertingBackslashToYenSymbol() const
 {
-    // If m_text isn't transcoded or is secure, we can just return the modified text.
-    if (!m_needsTranscoding || style()->textSecurity() != TSNONE)
+    if (!m_useBackslashAsYenSymbol || style()->textSecurity() != TSNONE)
         return text();
 
-    // Otherwise, we should use original text. If text-transform is
-    // specified, we should transform the text on the fly.
     String text = originalText();
     applyTextTransform(style(), text, previousCharacter());
     return text;
index 6592048..bc93c16 100644 (file)
@@ -56,7 +56,7 @@ public:
     void removeTextBox(InlineTextBox*);
 
     StringImpl* text() const { return m_text.impl(); }
-    String textWithoutTranscoding() const;
+    String textWithoutConvertingBackslashToYenSymbol() const;
 
     InlineTextBox* createInlineTextBox();
     void dirtyLineBoxes(bool fullLayout);
@@ -179,7 +179,7 @@ private:
     bool containsOnlyWhitespace(unsigned from, unsigned len) const;
     float widthFromCache(const Font&, int start, int len, float xPos, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow*) const;
     bool isAllASCII() const { return m_isAllASCII; }
-    void updateNeedsTranscoding();
+    bool computeUseBackslashAsYenSymbol() const;
 
     void secureText(UChar mask);
 
@@ -199,7 +199,7 @@ private:
     bool m_isAllASCII : 1;
     bool m_canUseSimpleFontCodePath : 1;
     mutable bool m_knownToHaveNoOverflowAndNoFallbackFonts : 1;
-    bool m_needsTranscoding : 1;
+    bool m_useBackslashAsYenSymbol : 1;
     
 #if ENABLE(IOS_TEXT_AUTOSIZING)
     // FIXME: This should probably be part of the text sizing structures in Document instead. That would save some memory.