Title: [206597] trunk/Source/WebCore
Revision
206597
Author
[email protected]
Date
2016-09-29 11:45:08 -0700 (Thu, 29 Sep 2016)

Log Message

[Win][Direct2D] Add D2D Font handling code
https://bugs.webkit.org/show_bug.cgi?id=162712

Reviewed by Brent Fulgham.

This patch lands a set of new files that implement

No new tests until complete backend lands.

* platform/graphics/Font.h:
* platform/graphics/FontCascade.h:
(WebCore::FontCascade::syntheticObliqueAngle): Added helper function.
* platform/graphics/FontPlatformData.h:
(WebCore::FontPlatformData::dwFont): Added.
(WebCore::FontPlatformData::dwFontFace): Ditto.
* platform/graphics/GlyphBuffer.h:
* platform/graphics/cocoa/FontCascadeCocoa.mm:
(WebCore::FontCascade::drawGlyphs): Use helper function.
* platform/graphics/win/FontCGWin.cpp:
(WebCore::FontCascade::drawGlyphs): Ditto.
* platform/graphics/win/FontCacheWin.cpp:
(WebCore::FontCache::createFontPlatformData): Add case for Direct2D.
* platform/graphics/win/FontCascadeDirect2D.cpp: Added.
* platform/graphics/win/FontCustomPlatformData.cpp:
(WebCore::FontCustomPlatformData::~FontCustomPlatformData): Fix whitespace.
(WebCore::FontCustomPlatformData::fontPlatformData): Add Direct2D case.
* platform/graphics/win/FontPlatformDataCGWin.cpp:
(WebCore::FontPlatformData::FontPlatformData): Clean up C++ initializers.
* platform/graphics/win/FontPlatformDataCairoWin.cpp:
(WebCore::FontPlatformData::FontPlatformData): Ditto.
* platform/graphics/win/FontPlatformDataDirect2D.cpp: Added.
* platform/graphics/win/FontPlatformDataWin.cpp:
(WebCore::FontPlatformData::FontPlatformData): Clean up C++ initializers.
* platform/graphics/win/GlyphPageTreeNodeDirect2D.cpp: Added.
* platform/graphics/win/SimpleFontDataDirect2D.cpp: Added.
* platform/graphics/win/TextAnalyzerHelper.cpp: Added.
* platform/graphics/win/TextAnalyzerHelper.h: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (206596 => 206597)


--- trunk/Source/WebCore/ChangeLog	2016-09-29 18:44:54 UTC (rev 206596)
+++ trunk/Source/WebCore/ChangeLog	2016-09-29 18:45:08 UTC (rev 206597)
@@ -1,3 +1,43 @@
+2016-09-29  Brent Fulgham  <[email protected]>
+
+        [Win][Direct2D] Add D2D Font handling code
+        https://bugs.webkit.org/show_bug.cgi?id=162712
+
+        Reviewed by Brent Fulgham.
+
+        This patch lands a set of new files that implement 
+
+        No new tests until complete backend lands.
+
+        * platform/graphics/Font.h:
+        * platform/graphics/FontCascade.h:
+        (WebCore::FontCascade::syntheticObliqueAngle): Added helper function.
+        * platform/graphics/FontPlatformData.h:
+        (WebCore::FontPlatformData::dwFont): Added.
+        (WebCore::FontPlatformData::dwFontFace): Ditto.
+        * platform/graphics/GlyphBuffer.h:
+        * platform/graphics/cocoa/FontCascadeCocoa.mm:
+        (WebCore::FontCascade::drawGlyphs): Use helper function.
+        * platform/graphics/win/FontCGWin.cpp:
+        (WebCore::FontCascade::drawGlyphs): Ditto.
+        * platform/graphics/win/FontCacheWin.cpp:
+        (WebCore::FontCache::createFontPlatformData): Add case for Direct2D.
+        * platform/graphics/win/FontCascadeDirect2D.cpp: Added.
+        * platform/graphics/win/FontCustomPlatformData.cpp:
+        (WebCore::FontCustomPlatformData::~FontCustomPlatformData): Fix whitespace.
+        (WebCore::FontCustomPlatformData::fontPlatformData): Add Direct2D case.
+        * platform/graphics/win/FontPlatformDataCGWin.cpp:
+        (WebCore::FontPlatformData::FontPlatformData): Clean up C++ initializers.
+        * platform/graphics/win/FontPlatformDataCairoWin.cpp:
+        (WebCore::FontPlatformData::FontPlatformData): Ditto.
+        * platform/graphics/win/FontPlatformDataDirect2D.cpp: Added.
+        * platform/graphics/win/FontPlatformDataWin.cpp:
+        (WebCore::FontPlatformData::FontPlatformData): Clean up C++ initializers.
+        * platform/graphics/win/GlyphPageTreeNodeDirect2D.cpp: Added.
+        * platform/graphics/win/SimpleFontDataDirect2D.cpp: Added.
+        * platform/graphics/win/TextAnalyzerHelper.cpp: Added.
+        * platform/graphics/win/TextAnalyzerHelper.h: Added.
+
 2016-09-29  Alex Christensen  <[email protected]>
 
         URLParser should fail to parse unclosed IPv6 addresses

Modified: trunk/Source/WebCore/platform/graphics/Font.h (206596 => 206597)


--- trunk/Source/WebCore/platform/graphics/Font.h	2016-09-29 18:44:54 UTC (rev 206596)
+++ trunk/Source/WebCore/platform/graphics/Font.h	2016-09-29 18:45:08 UTC (rev 206597)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the internal font implementation.
  *
- * Copyright (C) 2006, 2008, 2010, 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2008, 2010, 2015-2016 Apple Inc. All rights reserved.
  * Copyright (C) 2007-2008 Torch Mobile, Inc.
  *
  * This library is free software; you can redistribute it and/or
@@ -57,6 +57,11 @@
 #include "CoreGraphicsSPI.h"
 #endif
 
+#if USE(DIRECT2D)
+interface IDWriteFactory;
+interface IDWriteGdiInterop;
+#endif
+
 namespace WebCore {
 
 class GlyphPage;
@@ -143,7 +148,7 @@
         m_adjustedSpaceWidth = spaceWidth;
     }
 
-#if USE(CG) || USE(CAIRO)
+#if USE(CG) || USE(DIRECT2D) || USE(CAIRO)
     float syntheticBoldOffset() const { return m_syntheticBoldOffset; }
 #endif
 
@@ -198,6 +203,11 @@
     static float ascentConsideringMacAscentHack(const WCHAR*, float ascent, float descent);
 #endif
 
+#if USE(DIRECT2D)
+    WEBCORE_EXPORT static IDWriteFactory* systemDWriteFactory();
+    WEBCORE_EXPORT static IDWriteGdiInterop* systemDWriteGdiInterop();
+#endif
+
 private:
     Font(const FontPlatformData&, bool isCustomFont = false, bool isLoading = false, bool isTextOrientationFallback = false);
 
@@ -267,7 +277,7 @@
 
     mutable std::unique_ptr<DerivedFonts> m_derivedFontData;
 
-#if USE(CG) || USE(CAIRO)
+#if USE(CG) || USE(DIRECT2D) || USE(CAIRO)
     float m_syntheticBoldOffset;
 #endif
 
@@ -338,7 +348,7 @@
 
 #if ENABLE(OPENTYPE_VERTICAL)
     if (m_verticalData) {
-#if USE(CG) || USE(CAIRO)
+#if USE(CG) || USE(DIRECT2D) || USE(CAIRO)
         width = m_verticalData->advanceHeight(this, glyph) + m_syntheticBoldOffset;
 #else
         width = m_verticalData->advanceHeight(this, glyph);

Modified: trunk/Source/WebCore/platform/graphics/FontCascade.h (206596 => 206597)


--- trunk/Source/WebCore/platform/graphics/FontCascade.h	2016-09-29 18:44:54 UTC (rev 206596)
+++ trunk/Source/WebCore/platform/graphics/FontCascade.h	2016-09-29 18:45:08 UTC (rev 206597)
@@ -2,7 +2,7 @@
  * Copyright (C) 2000 Lars Knoll ([email protected])
  *           (C) 2000 Antti Koivisto ([email protected])
  *           (C) 2000 Dirk Mueller ([email protected])
- * Copyright (C) 2003, 2006, 2007, 2010, 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2003, 2006, 2007, 2010, 2011-2016 Apple Inc. All rights reserved.
  * Copyright (C) 2008 Holger Hans Peter Freyther
  *
  * This library is free software; you can redistribute it and/or
@@ -320,6 +320,8 @@
         return advancedTextRenderingMode();
     }
 
+    static int syntheticObliqueAngle() { return 14; }
+
     FontCascadeDescription m_fontDescription;
     mutable RefPtr<FontCascadeFonts> m_fonts;
     WeakPtrFactory<FontCascade> m_weakPtrFactory;

Modified: trunk/Source/WebCore/platform/graphics/FontPlatformData.h (206596 => 206597)


--- trunk/Source/WebCore/platform/graphics/FontPlatformData.h	2016-09-29 18:44:54 UTC (rev 206596)
+++ trunk/Source/WebCore/platform/graphics/FontPlatformData.h	2016-09-29 18:45:08 UTC (rev 206597)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2007, 2008, 2010, 2013 Apple Inc.
+ * Copyright (C) 2006, 2007, 2008, 2010, 2013-2016 Apple Inc.
  * Copyright (C) 2006 Michael Emmel [email protected]
  * Copyright (C) 2007 Holger Hans Peter Freyther
  * Copyright (C) 2007 Pioneer Research Center USA, Inc.
@@ -28,6 +28,7 @@
 #include "TextFlags.h"
 
 #if PLATFORM(WIN)
+#include "COMPtr.h"
 #include "SharedGDIObject.h"
 #endif
 
@@ -65,6 +66,8 @@
 #if PLATFORM(WIN)
 #include <wtf/win/GDIObject.h>
 typedef struct HFONT__* HFONT;
+interface IDWriteFont;
+interface IDWriteFontFace;
 #endif
 
 
@@ -103,6 +106,8 @@
 
 #if USE(CG)
     FontPlatformData(GDIObject<HFONT>, CGFontRef, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
+#elif USE(DIRECT2D)
+    FontPlatformData(GDIObject<HFONT>, IDWriteFont*, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
 #elif USE(CAIRO)
     FontPlatformData(GDIObject<HFONT>, cairo_font_face_t*, float size, bool bold, bool italic);
 #endif
@@ -137,6 +142,11 @@
     CGFontRef cgFont() const { return m_cgFont.get(); }
 #endif
 
+#if USE(DIRECT2D)
+    IDWriteFont* dwFont() const { return m_dwFont.get(); }
+    IDWriteFontFace* dwFontFace() const { return m_dwFontFace.get(); }
+#endif
+
     bool isFixedPitch() const;
     float size() const { return m_size; }
     bool syntheticBold() const { return m_syntheticBold; }
@@ -241,6 +251,10 @@
 #if USE(CG) && (PLATFORM(WIN) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED < 100000))
     RetainPtr<CGFontRef> m_cgFont;
 #endif
+#if USE(DIRECT2D)
+    COMPtr<IDWriteFont> m_dwFont;
+    COMPtr<IDWriteFontFace> m_dwFontFace;
+#endif
 #if USE(CAIRO)
     RefPtr<cairo_scaled_font_t> m_scaledFont;
 #endif

Modified: trunk/Source/WebCore/platform/graphics/GlyphBuffer.h (206596 => 206597)


--- trunk/Source/WebCore/platform/graphics/GlyphBuffer.h	2016-09-29 18:44:54 UTC (rev 206596)
+++ trunk/Source/WebCore/platform/graphics/GlyphBuffer.h	2016-09-29 18:45:08 UTC (rev 206597)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2009, 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2009, 2011, 2016 Apple Inc. All rights reserved.
  * Copyright (C) 2007-2008 Torch Mobile Inc.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -96,6 +96,7 @@
     GlyphBufferAdvance* advances(unsigned from) { return m_advances.data() + from; }
     const GlyphBufferGlyph* glyphs(unsigned from) const { return m_glyphs.data() + from; }
     const GlyphBufferAdvance* advances(unsigned from) const { return m_advances.data() + from; }
+    size_t advancesCount() const { return m_advances.size(); }
 
     const Font* fontAt(unsigned index) const { return m_font[index]; }
 

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm (206596 => 206597)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm	2016-09-29 18:44:54 UTC (rev 206596)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm	2016-09-29 18:45:08 UTC (rev 206597)
@@ -2,7 +2,7 @@
  * Copyright (C) 1999 Lars Knoll ([email protected])
  *           (C) 1999 Antti Koivisto ([email protected])
  *           (C) 2000 Dirk Mueller ([email protected])
- * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
+ * Copyright (C) 2003, 2006-2011, 2016 Apple Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -50,8 +50,6 @@
 SOFT_LINK(UIKit, _UIKitGetTextEffectsCatalog, CUICatalog *, (void), ())
 #endif
 
-#define SYNTHETIC_OBLIQUE_ANGLE 14
-
 #ifdef __LP64__
 #define URefCon void*
 #else
@@ -244,7 +242,7 @@
     matrix.b = -matrix.b;
     matrix.d = -matrix.d;
     if (platformData.syntheticOblique()) {
-        static float obliqueSkew = tanf(SYNTHETIC_OBLIQUE_ANGLE * piFloat / 180);
+        static float obliqueSkew = tanf(syntheticObliqueAngle() * piFloat / 180);
         if (platformData.orientation() == Vertical)
             matrix = CGAffineTransformConcat(matrix, CGAffineTransformMake(1, obliqueSkew, 0, 1, 0, 0));
         else

Modified: trunk/Source/WebCore/platform/graphics/win/FontCGWin.cpp (206596 => 206597)


--- trunk/Source/WebCore/platform/graphics/win/FontCGWin.cpp	2016-09-29 18:44:54 UTC (rev 206596)
+++ trunk/Source/WebCore/platform/graphics/win/FontCGWin.cpp	2016-09-29 18:45:08 UTC (rev 206597)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2007, 2008, 2009, 2013 Apple Inc.  All rights reserved.
+ * Copyright (C) 2006-2009, 2013, 2016 Apple Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -40,8 +40,6 @@
 
 namespace WebCore {
 
-const int syntheticObliqueAngle = 14;
-
 static inline CGFloat toCGFloat(FIXED f)
 {
     return f.value + f.fract / CGFloat(65536.0);
@@ -168,7 +166,7 @@
     matrix.d = -matrix.d;
 
     if (platformData.syntheticOblique()) {
-        static float skew = -tanf(syntheticObliqueAngle * piFloat / 180.0f);
+        static float skew = -tanf(syntheticObliqueAngle() * piFloat / 180.0f);
         matrix = CGAffineTransformConcat(matrix, CGAffineTransformMake(1, 0, skew, 1, 0, 0));
     }
 

Modified: trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp (206596 => 206597)


--- trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp	2016-09-29 18:44:54 UTC (rev 206596)
+++ trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp	2016-09-29 18:45:08 UTC (rev 206597)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2007, 2008, 2013-2014 Apple Inc.  All rights reserved.
+ * Copyright (C) 2006-2008, 2013-2014 Apple Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -47,6 +47,10 @@
 #include <WebKitSystemInterface/WebKitSystemInterface.h>
 #endif
 
+#if USE(DIRECT2D)
+#include <dwrite.h>
+#endif
+
 using std::min;
 
 namespace WebCore
@@ -549,6 +553,7 @@
     procData->m_traitsMasks.add(traitsMask);
     return 1;
 }
+
 Vector<FontTraitsMask> FontCache::getTraitsInFamily(const AtomicString& familyName)
 {
     HWndDC hdc(0);
@@ -599,6 +604,8 @@
 
 #if USE(CG)
     bool fontCreationFailed = !result->cgFont();
+#elif USE(DIRECT2D)
+    bool fontCreationFailed = !result->dwFont();
 #elif USE(CAIRO)
     bool fontCreationFailed = !result->scaledFont();
 #endif

Added: trunk/Source/WebCore/platform/graphics/win/FontCascadeDirect2D.cpp (0 => 206597)


--- trunk/Source/WebCore/platform/graphics/win/FontCascadeDirect2D.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/win/FontCascadeDirect2D.cpp	2016-09-29 18:45:08 UTC (rev 206597)
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2016 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 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 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 "FontCascade.h"
+
+#if USE(DIRECT2D)
+
+#include "AffineTransform.h"
+#include "COMPtr.h"
+#include "FloatConversion.h"
+#include "Font.h"
+#include "GlyphBuffer.h"
+#include "GraphicsContext.h"
+#include "GraphicsContextPlatformPrivateDirect2D.h"
+#include "IntRect.h"
+#include "UniscribeController.h"
+#include "WebCoreTextRenderer.h"
+#include <d2d1.h>
+#include <dwrite.h>
+#include <wtf/MathExtras.h>
+
+namespace WebCore {
+
+void FontCascade::drawGlyphs(GraphicsContext& graphicsContext, const Font& font, const GlyphBuffer& glyphBuffer,
+    unsigned from, unsigned numGlyphs, const FloatPoint& point, FontSmoothingMode smoothingMode)
+{
+    auto context = graphicsContext.platformContext();
+    bool shouldUseFontSmoothing = WebCoreShouldUseFontSmoothing();
+
+    switch (smoothingMode) {
+    case Antialiased:
+        graphicsContext.setShouldAntialias(true);
+        shouldUseFontSmoothing = false;
+        break;
+    case SubpixelAntialiased:
+        graphicsContext.setShouldAntialias(true);
+        shouldUseFontSmoothing = true;
+        break;
+    case NoSmoothing:
+        graphicsContext.setShouldAntialias(false);
+        shouldUseFontSmoothing = false;
+        break;
+    case AutoSmoothing:
+        // For the AutoSmooth case, don't do anything! Keep the default settings.
+        break;
+    default:
+        ASSERT_NOT_REACHED();
+    }
+
+    const FontPlatformData& platformData = font.platformData();
+
+    graphicsContext.save();
+
+    D2D1_MATRIX_3X2_F matrix;
+    context->GetTransform(&matrix);
+
+    if (platformData.syntheticOblique()) {
+        static float skew = -tanf(syntheticObliqueAngle() * piFloat / 180.0f);
+        auto skewMatrix = D2D1::Matrix3x2F::Skew(skew, 0);
+        context->SetTransform(matrix * skewMatrix);
+    }
+
+    // Uniscribe gives us offsets to help refine the positioning of combining glyphs.
+    FloatSize translation = glyphBuffer.offsetAt(from);
+
+    RELEASE_ASSERT(platformData.dwFont());
+    RELEASE_ASSERT(platformData.dwFontFace());
+
+    Vector<FLOAT> horizontalAdvances(numGlyphs);
+    Vector<DWRITE_GLYPH_OFFSET> offsetAdvances(numGlyphs);
+    for (unsigned i = 0; i < numGlyphs; ++i) {
+        if (i + from >= glyphBuffer.advancesCount())
+            break;
+
+        auto advance = glyphBuffer.advances(i + from);
+        if (!advance)
+            continue;
+
+        horizontalAdvances[i] = advance->width();
+        offsetAdvances[i].advanceOffset = advance->width();
+        offsetAdvances[i].ascenderOffset = advance->height();
+    }
+
+    DWRITE_GLYPH_RUN glyphRun;
+    glyphRun.fontFace = platformData.dwFontFace();
+    glyphRun.fontEmSize = platformData.size();
+    glyphRun.glyphCount = numGlyphs;
+    glyphRun.glyphIndices = glyphBuffer.glyphs(from);
+    glyphRun.glyphAdvances = horizontalAdvances.data();
+    glyphRun.glyphOffsets = nullptr;
+    glyphRun.isSideways = platformData.orientation() == Vertical;
+    glyphRun.bidiLevel = 0;
+
+    FloatSize shadowOffset;
+    float shadowBlur;
+    Color shadowColor;
+    graphicsContext.getShadow(shadowOffset, shadowBlur, shadowColor);
+
+    bool hasSimpleShadow = graphicsContext.textDrawingMode() == TextModeFill && shadowColor.isValid() && !shadowBlur && (!graphicsContext.shadowsIgnoreTransforms() || graphicsContext.getCTM().isIdentityOrTranslationOrFlipped());
+    if (hasSimpleShadow) {
+        // Paint simple shadows ourselves instead of relying on CG shadows, to avoid losing subpixel antialiasing.
+        graphicsContext.clearShadow();
+        Color fillColor = graphicsContext.fillColor();
+        Color shadowFillColor(shadowColor.red(), shadowColor.green(), shadowColor.blue(), shadowColor.alpha() * fillColor.alpha() / 255);
+        float shadowTextX = point.x() + translation.width() + shadowOffset.width();
+        // If shadows are ignoring transforms, then we haven't applied the Y coordinate flip yet, so down is negative.
+        float shadowTextY = point.y() + translation.height() + shadowOffset.height() * (graphicsContext.shadowsIgnoreTransforms() ? -1 : 1);
+
+        COMPtr<ID2D1SolidColorBrush> shadowBrush;
+        if (!SUCCEEDED(context->CreateSolidColorBrush(graphicsContext.colorWithGlobalAlpha(shadowFillColor), &shadowBrush)))
+            return;
+
+        context->DrawGlyphRun(D2D1::Point2F(shadowTextX, shadowTextY), &glyphRun, shadowBrush.get());
+        if (font.syntheticBoldOffset())
+            context->DrawGlyphRun(D2D1::Point2F(shadowTextX + font.syntheticBoldOffset(), shadowTextY), &glyphRun, shadowBrush.get());
+    }
+
+    context->DrawGlyphRun(D2D1::Point2F(point.x() + translation.width(), point.y() + translation.height()), &glyphRun, graphicsContext.solidFillBrush());
+    if (font.syntheticBoldOffset())
+        context->DrawGlyphRun(D2D1::Point2F(point.x() + translation.width() + font.syntheticBoldOffset(), point.y() + translation.height()), &glyphRun, graphicsContext.solidFillBrush());
+
+    if (hasSimpleShadow)
+        graphicsContext.setShadow(shadowOffset, shadowBlur, shadowColor);
+
+    graphicsContext.restore();
+}
+
+}
+
+#endif

Modified: trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformData.cpp (206596 => 206597)


--- trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformData.cpp	2016-09-29 18:44:54 UTC (rev 206596)
+++ trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformData.cpp	2016-09-29 18:45:08 UTC (rev 206597)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2007-2010, 2013, 2016 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -25,20 +25,26 @@
 #include "FontPlatformData.h"
 #include "OpenTypeUtilities.h"
 #include "SharedBuffer.h"
-#include <ApplicationServices/ApplicationServices.h>
-#include <WebKitSystemInterface/WebKitSystemInterface.h>
 #include <wtf/RetainPtr.h>
 #include <wtf/text/Base64.h>
 #include <wtf/win/GDIObject.h>
 
+#if USE(CG)
+#include <ApplicationServices/ApplicationServices.h>
+#include <WebKitSystemInterface/WebKitSystemInterface.h>
+#endif
+
+#if USE(DIRECT2D)
+#include "Font.h"
+#include <dwrite.h>
+#endif
+
 namespace WebCore {
 
-using namespace std;
-
 FontCustomPlatformData::~FontCustomPlatformData()
 {
     if (m_fontReference)
-            RemoveFontMemResourceEx(m_fontReference);
+        RemoveFontMemResourceEx(m_fontReference);
 }
 
 FontPlatformData FontCustomPlatformData::fontPlatformData(const FontDescription& fontDescription, bool bold, bool italic)
@@ -68,8 +74,15 @@
 
     auto hfont = adoptGDIObject(::CreateFontIndirect(&logFont));
 
+#if USE(CG)
     RetainPtr<CGFontRef> cgFont = adoptCF(CGFontCreateWithPlatformFont(&logFont));
     return FontPlatformData(WTFMove(hfont), cgFont.get(), size, bold, italic, renderingMode == FontRenderingMode::Alternate);
+#else
+    COMPtr<IDWriteFont> dwFont;
+    HRESULT hr = Font::systemDWriteGdiInterop()->CreateFontFromLOGFONT(&logFont, &dwFont);
+    RELEASE_ASSERT(SUCCEEDED(hr));
+    return FontPlatformData(WTFMove(hfont), dwFont.get(), size, bold, italic, renderingMode == FontRenderingMode::Alternate);
+#endif
 }
 
 // Creates a unique and unpredictable font name, in order to avoid collisions and to

Modified: trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformData.h (206596 => 206597)


--- trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformData.h	2016-09-29 18:44:54 UTC (rev 206596)
+++ trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformData.h	2016-09-29 18:45:08 UTC (rev 206597)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2007-2008, 2016 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public

Modified: trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.cpp (206596 => 206597)


--- trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.cpp	2016-09-29 18:44:54 UTC (rev 206596)
+++ trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.cpp	2016-09-29 18:45:08 UTC (rev 206597)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007, 2008, 2013 Apple Inc.
+ * Copyright (C) 2007-2008, 2013, 2016 Apple Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public

Modified: trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCGWin.cpp (206596 => 206597)


--- trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCGWin.cpp	2016-09-29 18:44:54 UTC (rev 206596)
+++ trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCGWin.cpp	2016-09-29 18:45:08 UTC (rev 206597)
@@ -2,7 +2,7 @@
  * 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, 2008, 2009 Apple Inc.
+ * Copyright (C) 2006-2009, 2016 Apple Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -120,12 +120,9 @@
 FontPlatformData::FontPlatformData(GDIObject<HFONT> hfont, CGFontRef font, float size, bool bold, bool oblique, bool useGDI)
     : m_syntheticBold(bold)
     , m_syntheticOblique(oblique)
-    , m_orientation(Horizontal)
     , m_size(size)
-    , m_widthVariant(RegularWidth)
     , m_font(SharedGDIObject<HFONT>::create(WTFMove(hfont)))
     , m_cgFont(font)
-    , m_isColorBitmapFont(false)
     , m_useGDI(useGDI)
 {
 }

Modified: trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCairoWin.cpp (206596 => 206597)


--- trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCairoWin.cpp	2016-09-29 18:44:54 UTC (rev 206596)
+++ trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCairoWin.cpp	2016-09-29 18:45:08 UTC (rev 206597)
@@ -2,7 +2,7 @@
  * 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, 2008 Apple Inc.
+ * Copyright (C) 2006-2008, 2016 Apple Inc.
  * Copyright (C) 2007 Alp Toker
  * Copyright (C) 2008, 2010, 2011 Brent Fulgham
  *
@@ -62,12 +62,7 @@
 FontPlatformData::FontPlatformData(GDIObject<HFONT> font, cairo_font_face_t* fontFace, float size, bool bold, bool oblique)
     : m_font(SharedGDIObject<HFONT>::create(WTFMove(font)))
     , m_size(size)
-    , m_orientation(Horizontal)
-    , m_widthVariant(RegularWidth)
-    , m_isColorBitmapFont(false)
-    , m_syntheticBold(bold)
     , m_syntheticOblique(oblique)
-    , m_useGDI(false)
 {
     cairo_matrix_t fontMatrix;
     cairo_matrix_init_scale(&fontMatrix, size, size);

Added: trunk/Source/WebCore/platform/graphics/win/FontPlatformDataDirect2D.cpp (0 => 206597)


--- trunk/Source/WebCore/platform/graphics/win/FontPlatformDataDirect2D.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/win/FontPlatformDataDirect2D.cpp	2016-09-29 18:45:08 UTC (rev 206597)
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2016 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 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 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 "FontPlatformData.h"
+
+#if USE(DIRECT2D)
+
+#include "GraphicsContext.h"
+#include "SharedGDIObject.h"
+#include <d2d1.h>
+#include <dwrite.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+void FontPlatformData::platformDataInit(HFONT font, float size, HDC hdc, WCHAR* faceName)
+{
+    LOGFONT logfont;
+    GetObject(font, sizeof(logfont), &logfont);
+
+    HRESULT hr = Font::systemDWriteGdiInterop()->CreateFontFromLOGFONT(&logfont, &m_dwFont);
+    if (!SUCCEEDED(hr))
+        return;
+
+    hr = m_dwFont->CreateFontFace(&m_dwFontFace);
+    if (!SUCCEEDED(hr))
+        return;
+
+    if (!m_useGDI)
+        m_isSystemFont = !wcscmp(faceName, L"Lucida Grande");
+}
+
+FontPlatformData::FontPlatformData(GDIObject<HFONT> hfont, IDWriteFont* font, float size, bool bold, bool oblique, bool useGDI)
+    : m_syntheticBold(bold)
+    , m_syntheticOblique(oblique)
+    , m_size(size)
+    , m_font(SharedGDIObject<HFONT>::create(WTFMove(hfont)))
+    , m_dwFont(font)
+    , m_useGDI(useGDI)
+{
+    HRESULT hr = m_dwFont->CreateFontFace(&m_dwFontFace);
+    RELEASE_ASSERT(SUCCEEDED(hr));
+}
+
+static bool fontsAreEqual(IDWriteFont* a, IDWriteFont* b)
+{
+    if (!a && !b)
+        return true;
+
+    if (a == b)
+        return true;
+
+    if ((!a && b) || (a && !b))
+        return false;
+
+    if (a->GetWeight() != b->GetWeight())
+        return false;
+
+    if (a->GetStyle() != b->GetStyle())
+        return false;
+
+    if (a->GetStretch() != b->GetStretch())
+        return false;
+
+    DWRITE_FONT_METRICS aMetrics, bMetrics;
+    a->GetMetrics(&aMetrics);
+    b->GetMetrics(&bMetrics);
+
+    if ((aMetrics.designUnitsPerEm != bMetrics.designUnitsPerEm)
+        || (aMetrics.ascent != bMetrics.ascent)
+        || (aMetrics.descent != bMetrics.ascent)
+        || (aMetrics.lineGap != bMetrics.lineGap)
+        || (aMetrics.capHeight != bMetrics.capHeight)
+        || (aMetrics.xHeight != bMetrics.xHeight)
+        || (aMetrics.underlinePosition != bMetrics.underlinePosition)
+        || (aMetrics.underlineThickness != bMetrics.underlineThickness)
+        || (aMetrics.strikethroughPosition != bMetrics.strikethroughPosition)
+        || (aMetrics.strikethroughThickness != bMetrics.strikethroughThickness))
+        return false;
+
+    return true;
+}
+
+bool FontPlatformData::platformIsEqual(const FontPlatformData& other) const
+{
+    return m_font == other.m_font
+        && m_useGDI == other.m_useGDI
+        && fontsAreEqual(m_dwFont.get(), other.m_dwFont.get());
+}
+
+}
+
+#endif

Modified: trunk/Source/WebCore/platform/graphics/win/FontPlatformDataWin.cpp (206596 => 206597)


--- trunk/Source/WebCore/platform/graphics/win/FontPlatformDataWin.cpp	2016-09-29 18:44:54 UTC (rev 206596)
+++ trunk/Source/WebCore/platform/graphics/win/FontPlatformDataWin.cpp	2016-09-29 18:45:08 UTC (rev 206597)
@@ -2,7 +2,7 @@
  * 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, 2008 Apple Inc.
+ * Copyright (C) 2006-2008, 2016 Apple Inc.
  * Copyright (C) 2008 Brent Fulgham
  *
  * This library is free software; you can redistribute it and/or
@@ -40,9 +40,6 @@
 FontPlatformData::FontPlatformData(GDIObject<HFONT> font, float size, bool bold, bool oblique, bool useGDI)
     : m_font(SharedGDIObject<HFONT>::create(WTFMove(font)))
     , m_size(size)
-    , m_orientation(Horizontal)
-    , m_widthVariant(RegularWidth)
-    , m_isColorBitmapFont(false)
     , m_syntheticBold(bold)
     , m_syntheticOblique(oblique)
     , m_useGDI(useGDI)

Modified: trunk/Source/WebCore/platform/graphics/win/FontWin.cpp (206596 => 206597)


--- trunk/Source/WebCore/platform/graphics/win/FontWin.cpp	2016-09-29 18:44:54 UTC (rev 206596)
+++ trunk/Source/WebCore/platform/graphics/win/FontWin.cpp	2016-09-29 18:45:08 UTC (rev 206597)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2007, 2008 Apple Inc.  All rights reserved.
+ * Copyright (C) 2006-2008, 2016 Apple Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions

Added: trunk/Source/WebCore/platform/graphics/win/GlyphPageTreeNodeDirect2D.cpp (0 => 206597)


--- trunk/Source/WebCore/platform/graphics/win/GlyphPageTreeNodeDirect2D.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/win/GlyphPageTreeNodeDirect2D.cpp	2016-09-29 18:45:08 UTC (rev 206597)
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2016 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 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 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 "GlyphPage.h"
+
+#if USE(DIRECT2D)
+
+#include "Font.h"
+#include "TextAnalysisHelper.h"
+#include <dwrite.h>
+
+namespace WebCore {
+
+bool GlyphPage::fill(UChar* buffer, unsigned bufferLength)
+{
+    if (bufferLength > GlyphPage::size)
+        return false;
+
+    const Font& font = this->font();
+    bool haveGlyphs = false;
+
+    COMPtr<IDWriteTextAnalyzer> analyzer;
+    HRESULT hr = Font::systemDWriteFactory()->CreateTextAnalyzer(&analyzer);
+    RELEASE_ASSERT(SUCCEEDED(hr));
+
+    auto& fontPlatformData = font.platformData();
+
+    UChar localeName[LOCALE_NAME_MAX_LENGTH + 1] = { };
+    int localeLength = GetUserDefaultLocaleName(reinterpret_cast<LPWSTR>(&localeName), LOCALE_NAME_MAX_LENGTH);
+    RELEASE_ASSERT(localeLength <= LOCALE_NAME_MAX_LENGTH);
+    localeName[localeLength] = '\0';
+
+    TextAnalyzerHelper helper(localeName, buffer, bufferLength);
+
+    hr = analyzer->AnalyzeScript(&helper, 0, bufferLength, &helper);
+    RELEASE_ASSERT(SUCCEEDED(hr));
+
+    unsigned returnedCount = 0;
+    Glyph localGlyphBuffer[GlyphPage::size];
+    Glyph clusterMap[GlyphPage::size];
+    Vector<DWRITE_SHAPING_TEXT_PROPERTIES> textProperties(GlyphPage::size);
+    Vector<DWRITE_SHAPING_GLYPH_PROPERTIES> glyphProperties(GlyphPage::size);
+
+    hr = analyzer->GetGlyphs(buffer, bufferLength, fontPlatformData.dwFontFace(), fontPlatformData.orientation() == Vertical, false,
+        &helper.m_analysis, nullptr, nullptr, nullptr, nullptr, 0, GlyphPage::size, clusterMap, textProperties.data(),
+        localGlyphBuffer, glyphProperties.data(), &returnedCount);
+    RELEASE_ASSERT(SUCCEEDED(hr));
+
+    for (unsigned i = 0; i < GlyphPage::size; i++) {
+        Glyph glyph = localGlyphBuffer[i];
+        if (!glyph)
+            setGlyphForIndex(i, 0);
+        else {
+            setGlyphForIndex(i, glyph);
+            haveGlyphs = true;
+        }
+    }
+
+    return haveGlyphs;
+}
+
+}
+
+#endif

Added: trunk/Source/WebCore/platform/graphics/win/SimpleFontDataDirect2D.cpp (0 => 206597)


--- trunk/Source/WebCore/platform/graphics/win/SimpleFontDataDirect2D.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/win/SimpleFontDataDirect2D.cpp	2016-09-29 18:45:08 UTC (rev 206597)
@@ -0,0 +1,235 @@
+/*
+ * Copyright (C) 2016 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 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 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 "Font.h"
+
+#if USE(DIRECT2D)
+
+#include "CoreTextSPIWin.h"
+#include "FloatRect.h"
+#include "FontCache.h"
+#include "FontDescription.h"
+#include "GlyphPage.h"
+#include "GraphicsContext.h"
+#include "HWndDC.h"
+#include <comutil.h>
+#include <dwrite.h>
+#include <mlang.h>
+#include <unicode/uchar.h>
+#include <unicode/unorm.h>
+#include <winsock2.h>
+#include <wtf/MathExtras.h>
+#include <wtf/RetainPtr.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+IDWriteFactory* Font::systemDWriteFactory()
+{
+    static IDWriteFactory* directWriteFactory = nullptr;
+    if (!directWriteFactory) {
+        HRESULT hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(directWriteFactory), reinterpret_cast<IUnknown**>(&directWriteFactory));
+        RELEASE_ASSERT(SUCCEEDED(hr));
+    }
+
+    return directWriteFactory;
+}
+
+IDWriteGdiInterop* Font::systemDWriteGdiInterop()
+{
+    static IDWriteGdiInterop* directWriteGdiInterop = nullptr;
+    if (!directWriteGdiInterop) {
+        HRESULT hr = systemDWriteFactory()->GetGdiInterop(&directWriteGdiInterop);
+        RELEASE_ASSERT(SUCCEEDED(hr));
+    }
+
+    return directWriteGdiInterop;
+}
+
+static Vector<WCHAR> getFaceName(IDWriteFont* font)
+{
+    if (!font)
+        return Vector<WCHAR>();
+
+    COMPtr<IDWriteLocalizedStrings> localizedFaceNames;
+    HRESULT hr = font->GetFaceNames(&localizedFaceNames);
+    RELEASE_ASSERT(SUCCEEDED(hr));
+
+    UINT32 localeIndex = 0;
+    BOOL exists = false;
+
+    wchar_t localeName[LOCALE_NAME_MAX_LENGTH];
+    int localeLength = GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH);
+    if (localeLength)
+        hr = localizedFaceNames->FindLocaleName(localeName, &localeIndex, &exists);
+
+    if (!exists || !SUCCEEDED(hr))
+        hr = localizedFaceNames->FindLocaleName(L"en-us", &localeIndex, &exists);
+
+    if (!exists || !SUCCEEDED(hr))
+        localeIndex = 0;
+
+    UINT32 faceNameLength = 0;
+    hr = localizedFaceNames->GetStringLength(localeIndex, &faceNameLength);
+    if (!SUCCEEDED(hr))
+        return Vector<WCHAR>();
+
+    Vector<WCHAR> faceName(faceNameLength + 1);
+    hr = localizedFaceNames->GetString(localeIndex, faceName.data(), faceName.size());
+
+    return faceName;
+}
+
+void Font::platformInit()
+{
+    m_syntheticBoldOffset = m_platformData.syntheticBold() ? 1.0f : 0.f;
+    m_scriptCache = 0;
+    m_scriptFontProperties = 0;
+
+    if (m_platformData.useGDI())
+        return initGDIFont();
+
+    float pointSize = m_platformData.size();
+
+    auto font = m_platformData.dwFont();
+    RELEASE_ASSERT(font);
+
+    auto fontFace = m_platformData.dwFontFace();
+    RELEASE_ASSERT(fontFace);
+
+    DWRITE_FONT_METRICS fontMetrics;
+    font->GetMetrics(&fontMetrics);
+
+    int iAscent = fontMetrics.ascent;
+    int iDescent = fontMetrics.descent;
+    int iLineGap = fontMetrics.lineGap;
+    int iCapHeight = fontMetrics.capHeight;
+
+    unsigned unitsPerEm = fontMetrics.designUnitsPerEm;
+    float fAscent = scaleEmToUnits(iAscent, unitsPerEm) * pointSize;
+    float fDescent = scaleEmToUnits(iDescent, unitsPerEm) * pointSize;
+    float fCapHeight = scaleEmToUnits(iCapHeight, unitsPerEm) * pointSize;
+    float fLineGap = scaleEmToUnits(iLineGap, unitsPerEm) * pointSize;
+
+    if (!isCustomFont()) {
+        Vector<WCHAR> faceName = getFaceName(font);
+        fAscent = ascentConsideringMacAscentHack(faceName.data(), fAscent, fDescent);
+    }
+
+    m_fontMetrics.setAscent(fAscent);
+    m_fontMetrics.setDescent(fDescent);
+    m_fontMetrics.setCapHeight(fCapHeight);
+    m_fontMetrics.setLineGap(fLineGap);
+    m_fontMetrics.setLineSpacing(lroundf(fAscent) + lroundf(fDescent) + lroundf(fLineGap));
+
+    Glyph xGlyph = glyphDataForCharacter('x').glyph;
+
+    if (xGlyph) {
+        // Measure the actual character "x", since it's possible for it to extend below the baseline, and we need the
+        // reported x-height to only include the portion of the glyph that is above the baseline.
+        Vector<DWRITE_GLYPH_METRICS> glyphMetrics(1);
+        HRESULT hr = fontFace->GetDesignGlyphMetrics(&xGlyph, 1, glyphMetrics.data(), m_platformData.orientation() == Vertical);
+        RELEASE_ASSERT(SUCCEEDED(hr));
+        m_fontMetrics.setXHeight(scaleEmToUnits(glyphMetrics.first().verticalOriginY, unitsPerEm) * pointSize);
+    } else {
+        int iXHeight = fontMetrics.xHeight;
+        m_fontMetrics.setXHeight(scaleEmToUnits(iXHeight, unitsPerEm) * pointSize);
+    }
+
+    m_fontMetrics.setUnitsPerEm(unitsPerEm);
+}
+
+FloatRect Font::platformBoundsForGlyph(Glyph glyph) const
+{
+    if (!platformData().size())
+        return FloatRect();
+
+    if (m_platformData.useGDI())
+        return boundsForGDIGlyph(glyph);
+
+    auto font = m_platformData.dwFont();
+    RELEASE_ASSERT(font);
+
+    auto fontFace = m_platformData.dwFontFace();
+    RELEASE_ASSERT(fontFace);
+
+    float pointSize = m_platformData.size();
+    bool vertical = m_platformData.orientation() == Vertical;
+
+    Vector<DWRITE_GLYPH_METRICS> glyphMetrics(1);
+    HRESULT hr = fontFace->GetDesignGlyphMetrics(&glyph, 1, glyphMetrics.data(), m_platformData.orientation() == Vertical);
+    RELEASE_ASSERT(SUCCEEDED(hr));
+
+    const auto& metrics = glyphMetrics.first();
+
+    unsigned unitsPerEm = m_fontMetrics.unitsPerEm();
+
+    FloatPoint origin(scaleEmToUnits(metrics.leftSideBearing, unitsPerEm) * pointSize, scaleEmToUnits(metrics.verticalOriginY, unitsPerEm) * pointSize);
+    FloatSize size(scaleEmToUnits(metrics.advanceWidth - metrics.leftSideBearing - metrics.rightSideBearing, unitsPerEm) * pointSize,
+        scaleEmToUnits(metrics.advanceHeight - metrics.topSideBearing - metrics.bottomSideBearing, unitsPerEm) * pointSize);
+
+    FloatRect boundingBox(origin, size);
+    if (m_syntheticBoldOffset)
+        boundingBox.setWidth(boundingBox.width() + m_syntheticBoldOffset);
+
+    return boundingBox;
+}
+
+float Font::platformWidthForGlyph(Glyph glyph) const
+{
+    if (!platformData().size())
+        return 0;
+
+    if (m_platformData.useGDI())
+        return widthForGDIGlyph(glyph);
+
+    ASSERT(glyph);
+
+    auto font = m_platformData.dwFont();
+    RELEASE_ASSERT(font);
+
+    auto fontFace = m_platformData.dwFontFace();
+    RELEASE_ASSERT(fontFace);
+
+    bool isVertical = m_platformData.orientation() == Vertical;
+
+    Vector<DWRITE_GLYPH_METRICS> glyphMetrics(1);
+    HRESULT hr = fontFace->GetDesignGlyphMetrics(&glyph, 1, glyphMetrics.data(), isVertical);
+    RELEASE_ASSERT(SUCCEEDED(hr));
+
+    const auto& metrics = glyphMetrics.first();
+    int widthInEm = metrics.advanceWidth;
+
+    float pointSize = m_platformData.size();
+    unsigned unitsPerEm = m_fontMetrics.unitsPerEm();
+    float width = scaleEmToUnits(widthInEm, unitsPerEm) * pointSize;
+
+    return width + m_syntheticBoldOffset;
+}
+
+}
+
+#endif

Added: trunk/Source/WebCore/platform/graphics/win/TextAnalyzerHelper.cpp (0 => 206597)


--- trunk/Source/WebCore/platform/graphics/win/TextAnalyzerHelper.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/win/TextAnalyzerHelper.cpp	2016-09-29 18:45:08 UTC (rev 206597)
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2016 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 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 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 "TextAnalyzerHelper.h"
+
+#if USE(DIRECT2D)
+
+namespace WebCore {
+
+TextAnalyzerHelper::TextAnalyzerHelper(WCHAR* localeName, WCHAR* buffer, unsigned bufferLength)
+    : m_localeName(localeName)
+    , m_buffer(buffer)
+    , m_bufferLength(bufferLength)
+{
+}
+
+HRESULT TextAnalyzerHelper::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject)
+{
+    if (!ppvObject)
+        return E_POINTER;
+    *ppvObject = nullptr;
+    if (IsEqualGUID(riid, __uuidof(IDWriteTextAnalysisSink)))
+        *ppvObject = static_cast<IDWriteTextAnalysisSink*>(this);
+    else if (IsEqualGUID(riid, __uuidof(IDWriteTextAnalysisSource)))
+        *ppvObject = static_cast<IDWriteTextAnalysisSink*>(this);
+    else
+        return E_FAIL;
+
+    AddRef();
+    return S_OK;
+}
+
+ULONG TextAnalyzerHelper::AddRef()
+{
+    return ++m_refCount;
+}
+
+ULONG TextAnalyzerHelper::Release()
+{
+    ULONG newRef = --m_refCount;
+    if (!newRef)
+        delete(this);
+
+    return newRef;
+}
+
+HRESULT TextAnalyzerHelper::GetTextAtPosition(UINT32 textPosition, const WCHAR** textString, UINT32* textLength)
+{
+    if (!textString || !textLength)
+        return E_POINTER;
+
+    if (textPosition >= m_bufferLength) {
+        *textString = nullptr;
+        *textLength = 0;
+        return S_OK;
+    }
+
+    *textString = &m_buffer[textPosition];
+    *textLength = m_bufferLength - textPosition;
+
+    return S_OK;
+}
+
+HRESULT TextAnalyzerHelper::GetTextBeforePosition(UINT32 textPosition, const WCHAR** textString, UINT32* textLength)
+{
+    if (!textString || !textLength)
+        return E_POINTER;
+
+    if (!textPosition || textPosition > m_bufferLength) {
+        *textString = nullptr;
+        *textLength = 0;
+        return S_OK;
+    }
+
+    *textString = &m_buffer[0];
+    *textLength = textPosition;
+
+    return S_OK;
+}
+
+HRESULT TextAnalyzerHelper::GetLocaleName(UINT32 textPosition, UINT32* textLength, const WCHAR** localeName)
+{
+    *localeName = m_localeName;
+    *textLength = m_bufferLength - textPosition;
+
+    return S_OK;
+}
+
+HRESULT TextAnalyzerHelper::GetNumberSubstitution(UINT32 textPosition, UINT32* textLength, IDWriteNumberSubstitution** numberSubstitution)
+{
+    *textLength = m_bufferLength - textPosition;
+    return S_OK;
+}
+
+HRESULT TextAnalyzerHelper::SetLineBreakpoints(UINT32 textPosition, UINT32 textLength, const DWRITE_LINE_BREAKPOINT*)
+{
+    return E_NOTIMPL;
+}
+
+HRESULT TextAnalyzerHelper::SetScriptAnalysis(UINT32 textPosition, UINT32 textLength, const DWRITE_SCRIPT_ANALYSIS* analysis)
+{
+    m_analysis = *analysis;
+
+    return S_OK;
+}
+
+HRESULT TextAnalyzerHelper::SetBidiLevel(UINT32 textPosition, UINT32 textLength, UINT8 explicitLevel, UINT8 resolvedLevel)
+{
+    return E_NOTIMPL;
+}
+
+HRESULT TextAnalyzerHelper::SetNumberSubstitution(UINT32 textPosition, UINT32 textLength, IDWriteNumberSubstitution*)
+{
+    return E_NOTIMPL;
+}
+
+}
+
+#endif

Added: trunk/Source/WebCore/platform/graphics/win/TextAnalyzerHelper.h (0 => 206597)


--- trunk/Source/WebCore/platform/graphics/win/TextAnalyzerHelper.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/win/TextAnalyzerHelper.h	2016-09-29 18:45:08 UTC (rev 206597)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2016 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 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 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. 
+ */
+
+#pragma once
+
+#include <dwrite.h>
+
+namespace WebCore {
+
+struct TextAnalyzerHelper : public IDWriteTextAnalysisSink, IDWriteTextAnalysisSource {
+    TextAnalyzerHelper(WCHAR* localeName, WCHAR* buffer, unsigned bufferLength);
+
+    // IUnknown
+    virtual HRESULT STDMETHODCALLTYPE QueryInterface(_In_ REFIID, _COM_Outptr_ void**);
+    virtual ULONG STDMETHODCALLTYPE AddRef();
+    virtual ULONG STDMETHODCALLTYPE Release();
+
+    // IDWriteTextAnalysisSource 
+    virtual HRESULT STDMETHODCALLTYPE GetTextAtPosition(UINT32 textPosition, const WCHAR** textString, UINT32* textLength);
+    virtual HRESULT STDMETHODCALLTYPE GetTextBeforePosition(UINT32 textPosition, const WCHAR** textString, UINT32* textLength);
+    virtual DWRITE_READING_DIRECTION STDMETHODCALLTYPE GetParagraphReadingDirection() { return DWRITE_READING_DIRECTION_LEFT_TO_RIGHT; }
+    virtual HRESULT STDMETHODCALLTYPE GetLocaleName(UINT32 textPosition, UINT32* textLength, const WCHAR** localeName);
+    virtual HRESULT STDMETHODCALLTYPE GetNumberSubstitution(UINT32 textPosition, UINT32* textLength, IDWriteNumberSubstitution**);
+
+    // IDWriteTextAnalysisSink
+    virtual HRESULT STDMETHODCALLTYPE SetLineBreakpoints(UINT32 textPosition, UINT32 textLength, const DWRITE_LINE_BREAKPOINT*);
+    virtual HRESULT STDMETHODCALLTYPE SetScriptAnalysis(UINT32 textPosition, UINT32 textLength, const DWRITE_SCRIPT_ANALYSIS*);
+    virtual HRESULT STDMETHODCALLTYPE SetBidiLevel(UINT32 textPosition, UINT32 textLength, UINT8 explicitLevel, UINT8 resolvedLevel);
+    virtual HRESULT STDMETHODCALLTYPE SetNumberSubstitution(UINT32 textPosition, UINT32 textLength, IDWriteNumberSubstitution*);
+
+    WCHAR* m_localeName { nullptr };
+    WCHAR* m_buffer { nullptr };
+    unsigned m_bufferLength { 0 };
+    DWRITE_SCRIPT_ANALYSIS m_analysis { };
+    ULONG m_refCount { 0 };
+};
+
+}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to