Upstream version 11.39.266.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / platform / fonts / skia / SimpleFontDataSkia.cpp
index 99396f4..47e73c4 100644 (file)
 #include "SkPath.h"
 #include "SkTypeface.h"
 #include "SkTypes.h"
+#include "SkUtils.h"
 #include "platform/fonts/FontDescription.h"
+#include "platform/fonts/GlyphPage.h"
 #include "platform/fonts/VDMXParser.h"
 #include "platform/geometry/FloatRect.h"
 #include "wtf/unicode/Unicode.h"
 
-#if OS(WIN)
-#include "platform/win/HWndDC.h"
-#endif
-
-namespace WebCore {
+namespace blink {
 
 // This is the largest VDMX table which we'll try to load and parse.
 static const size_t maxVDMXTableSize = 1024 * 1024; // 1 MB
@@ -133,12 +131,6 @@ void SimpleFontData::platformInit()
     m_fontMetrics.setLineGap(lineGap);
     m_fontMetrics.setLineSpacing(lroundf(ascent) + lroundf(descent) + lroundf(lineGap));
 
-    // For now Skia does not support underline Thickness, once patch is comitted we can uncomment following
-    // code, till then setting Underline Thickness to Zero so that default calculation is done.
-    // float underlineThickness = SkScalarToFloat(metrics.fUnderlineThickness);
-    // m_fontMetrics.setUnderlineThickness(underlineThickness);
-    m_fontMetrics.setUnderlineThickness(0.f);
-
     if (platformData().orientation() == Vertical && !isTextOrientationFallback()) {
         static const uint32_t vheaTag = SkSetFourByteTag('v', 'h', 'e', 'a');
         static const uint32_t vorgTag = SkSetFourByteTag('V', 'O', 'R', 'G');
@@ -153,6 +145,12 @@ void SimpleFontData::platformInit()
     // m_avgCharWidth in order for text entry widgets to be sized correctly.
 #if OS(WIN)
     m_maxCharWidth = SkScalarRoundToInt(metrics.fMaxCharWidth);
+
+    // Older version of the DirectWrite API doesn't implement support for max
+    // char width. Fall back on a multiple of the ascent. This is entirely
+    // arbitrary but comes pretty close to the expected value in most cases.
+    if (m_maxCharWidth < 1)
+        m_maxCharWidth = ascent * 2;
 #else
     // FIXME: This seems incorrect and should probably use fMaxCharWidth as
     // the code path above.
@@ -198,7 +196,7 @@ void SimpleFontData::platformDestroy()
 PassRefPtr<SimpleFontData> SimpleFontData::platformCreateScaledFontData(const FontDescription& fontDescription, float scaleFactor) const
 {
     const float scaledSize = lroundf(fontDescription.computedSize() * scaleFactor);
-    return SimpleFontData::create(FontPlatformData(m_platformData, scaledSize), isCustomFont() ? CustomFontData::create(false) : 0);
+    return SimpleFontData::create(FontPlatformData(m_platformData, scaledSize), isCustomFont() ? CustomFontData::create() : nullptr);
 }
 
 void SimpleFontData::determinePitch()
@@ -254,7 +252,6 @@ float SimpleFontData::platformWidthForGlyph(Glyph glyph) const
     return SkScalarToFloat(width);
 }
 
-#if USE(HARFBUZZ)
 bool SimpleFontData::canRenderCombiningCharacterSequence(const UChar* characters, size_t length) const
 {
     if (!m_combiningCharacterSequenceSupport)
@@ -280,6 +277,29 @@ bool SimpleFontData::canRenderCombiningCharacterSequence(const UChar* characters
     }
     return false;
 }
-#endif
 
-} // namespace WebCore
+bool SimpleFontData::fillGlyphPage(GlyphPage* pageToFill, unsigned offset, unsigned length, UChar* buffer, unsigned bufferLength) const
+{
+    if (SkUTF16_IsHighSurrogate(buffer[bufferLength-1])) {
+        SkDebugf("%s last char is high-surrogate", __FUNCTION__);
+        return false;
+    }
+
+    SkAutoSTMalloc<GlyphPage::size, uint16_t> glyphStorage(length);
+
+    uint16_t* glyphs = glyphStorage.get();
+    SkTypeface* typeface = platformData().typeface();
+    typeface->charsToGlyphs(buffer, SkTypeface::kUTF16_Encoding, glyphs, length);
+
+    bool haveGlyphs = false;
+    for (unsigned i = 0; i < length; i++) {
+        if (glyphs[i]) {
+            pageToFill->setGlyphDataForIndex(offset + i, glyphs[i], this);
+            haveGlyphs = true;
+        }
+    }
+
+    return haveGlyphs;
+}
+
+} // namespace blink