Title: [151743] trunk/Source/WebCore
Revision
151743
Author
[email protected]
Date
2013-06-19 11:17:26 -0700 (Wed, 19 Jun 2013)

Log Message

[WinCairo] Webfont rendering is broken.
https://bugs.webkit.org/show_bug.cgi?id=117695

Patch by [email protected] <[email protected]> on 2013-06-19
Reviewed by Brent Fulgham.

The native font handle created from webfont data is invalid.
In much the same way it's done in WinApple, we first need to install the webfont,
create a native font handle from the new font name,
and pass the font handle to the FontPlatformData object, where it's needed to get the glyphs.

* platform/graphics/FontPlatformData.h: Added HFONT parameter to constructor.
* platform/graphics/win/FontCustomPlatformDataCairo.cpp:
(WebCore::FontCustomPlatformData::~FontCustomPlatformData): Release installed webfont.
(WebCore::FontCustomPlatformData::fontPlatformData): Create valid HFONT handle for webfont.
(WebCore::createUniqueFontName): Added method to create webfont name.
(WebCore::createFontCustomPlatformData): Install font from webfont data.
* platform/graphics/win/FontCustomPlatformDataCairo.h: Removed.
* platform/graphics/win/FontPlatformDataCairoWin.cpp:
(WebCore::FontPlatformData::FontPlatformData): Added HFONT parameter to constructor.

Modified Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (151742 => 151743)


--- trunk/Source/WebCore/ChangeLog	2013-06-19 18:05:50 UTC (rev 151742)
+++ trunk/Source/WebCore/ChangeLog	2013-06-19 18:17:26 UTC (rev 151743)
@@ -1,3 +1,25 @@
+2013-06-19  [email protected]  <[email protected]>
+
+        [WinCairo] Webfont rendering is broken.
+        https://bugs.webkit.org/show_bug.cgi?id=117695
+
+        Reviewed by Brent Fulgham.
+
+        The native font handle created from webfont data is invalid.
+        In much the same way it's done in WinApple, we first need to install the webfont,
+        create a native font handle from the new font name,
+        and pass the font handle to the FontPlatformData object, where it's needed to get the glyphs.
+
+        * platform/graphics/FontPlatformData.h: Added HFONT parameter to constructor.
+        * platform/graphics/win/FontCustomPlatformDataCairo.cpp:
+        (WebCore::FontCustomPlatformData::~FontCustomPlatformData): Release installed webfont.
+        (WebCore::FontCustomPlatformData::fontPlatformData): Create valid HFONT handle for webfont.
+        (WebCore::createUniqueFontName): Added method to create webfont name.
+        (WebCore::createFontCustomPlatformData): Install font from webfont data.
+        * platform/graphics/win/FontCustomPlatformDataCairo.h: Removed.
+        * platform/graphics/win/FontPlatformDataCairoWin.cpp:
+        (WebCore::FontPlatformData::FontPlatformData): Added HFONT parameter to constructor.
+
 2013-06-19  Christophe Dumez  <[email protected]>
 
         Implement WebIDL implements

Modified: trunk/Source/WebCore/platform/graphics/FontPlatformData.h (151742 => 151743)


--- trunk/Source/WebCore/platform/graphics/FontPlatformData.h	2013-06-19 18:05:50 UTC (rev 151742)
+++ trunk/Source/WebCore/platform/graphics/FontPlatformData.h	2013-06-19 18:17:26 UTC (rev 151743)
@@ -103,11 +103,10 @@
     FontPlatformData(HFONT, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
 #if USE(CG)
     FontPlatformData(HFONT, CGFontRef, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
+#elif USE(CAIRO)
+    FontPlatformData(HFONT, cairo_font_face_t*, float size, bool bold, bool italic);
 #endif
 #endif
-#if USE(CAIRO)
-    FontPlatformData(cairo_font_face_t*, float size, bool bold, bool italic);
-#endif
 
     ~FontPlatformData();
 

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


--- trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.cpp	2013-06-19 18:05:50 UTC (rev 151742)
+++ trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.cpp	2013-06-19 18:17:26 UTC (rev 151743)
@@ -19,46 +19,77 @@
  */
 
 #include "config.h"
-#include "FontCustomPlatformDataCairo.h"
+#include "FontCustomPlatformData.h"
 
+#include "OpenTypeUtilities.h"
 #include "SharedBuffer.h"
 #include "FontPlatformData.h"
 
 #include <cairo-win32.h>
 #include <wtf/RetainPtr.h>
+#include <wtf/text/Base64.h>
 
-
 namespace WebCore {
 
 FontCustomPlatformData::~FontCustomPlatformData()
 {
-   cairo_font_face_destroy(m_fontFace);
+    if (m_fontReference)
+        RemoveFontMemResourceEx(m_fontReference);
 }
 
-FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, bool italic, FontOrientation, FontWidthVariant, FontRenderingMode)
+FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, bool italic, FontOrientation, FontWidthVariant, FontRenderingMode renderingMode)
 {
-    return FontPlatformData(m_fontFace, size, bold, italic);
+    LOGFONT logFont;
+    memset(&logFont, 0, sizeof(LOGFONT));
+    wcsncpy(logFont.lfFaceName, m_name.charactersWithNullTermination(), LF_FACESIZE - 1);
+
+    logFont.lfHeight = -size;
+    if (renderingMode == NormalRenderingMode)
+        logFont.lfHeight *= 32;
+    logFont.lfWidth = 0;
+    logFont.lfEscapement = 0;
+    logFont.lfOrientation = 0;
+    logFont.lfUnderline = false;
+    logFont.lfStrikeOut = false;
+    logFont.lfCharSet = DEFAULT_CHARSET;
+    logFont.lfOutPrecision = OUT_TT_ONLY_PRECIS;
+    logFont.lfQuality = CLEARTYPE_QUALITY;
+    logFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
+    logFont.lfItalic = italic;
+    logFont.lfWeight = bold ? 700 : 400;
+
+    HFONT hfont = CreateFontIndirect(&logFont);
+
+    cairo_font_face_t* fontFace = cairo_win32_font_face_create_for_hfont(hfont);
+
+    FontPlatformData fontPlatformData(hfont, fontFace, size, bold, italic);
+
+    cairo_font_face_destroy(fontFace);
+
+    return fontPlatformData;
 }
 
-static void releaseData(void* data)
+static String createUniqueFontName()
 {
-    static_cast<SharedBuffer*>(data)->deref();
+    GUID fontUuid;
+    CoCreateGuid(&fontUuid);
+
+    String fontName = base64Encode(reinterpret_cast<char*>(&fontUuid), sizeof(fontUuid));
+    ASSERT(fontName.length() < LF_FACESIZE);
+    return fontName;
 }
 
 FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
 {
     ASSERT_ARG(buffer, buffer);
 
-    buffer->ref();
-    HFONT font = reinterpret_cast<HFONT>(buffer);
-    cairo_font_face_t* fontFace = cairo_win32_font_face_create_for_hfont(font);
-    if (!fontFace)
-       return 0;
+    String fontName = createUniqueFontName();
+    HANDLE fontReference = renameAndActivateFont(buffer, fontName);
 
-    static cairo_user_data_key_t bufferKey;
-    cairo_font_face_set_user_data(fontFace, &bufferKey, buffer, releaseData);
+    if (!fontReference)
+        return 0;
 
-    return new FontCustomPlatformData(fontFace);
+    return new FontCustomPlatformData(fontReference, fontName);
 }
 
 bool FontCustomPlatformData::supportsFormat(const String& format)

Deleted: trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.h (151742 => 151743)


--- trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.h	2013-06-19 18:05:50 UTC (rev 151742)
+++ trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.h	2013-06-19 18:17:26 UTC (rev 151743)
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2007 Apple Computer, Inc.
- * Copyright (C) 2010 Brent Fulgham <[email protected]>
- *
- * 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 FontCustomPlatformDataCairo_h
-#define FontCustomPlatformDataCairo_h
-
-#include "FontDescription.h"
-#include <wtf/Forward.h>
-#include <wtf/Noncopyable.h>
-
-#include <cairo.h>
-
-namespace WebCore {
-
-class FontPlatformData;
-class SharedBuffer;
-
-struct FontCustomPlatformData {
-    WTF_MAKE_NONCOPYABLE(FontCustomPlatformData);
-public:
-    FontCustomPlatformData(cairo_font_face_t* fontFace)
-        : m_fontFace(fontFace)
-    {
-    }
-    ~FontCustomPlatformData();
-
-    FontPlatformData fontPlatformData(int size, bool bold, bool italic, FontOrientation = Horizontal, FontWidthVariant = RegularWidth, FontRenderingMode = NormalRenderingMode);
-
-    static bool supportsFormat(const String&);
-
-    cairo_font_face_t* m_fontFace;
-};
-
-FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer*);
-
-}
-
-#endif

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


--- trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCairoWin.cpp	2013-06-19 18:05:50 UTC (rev 151742)
+++ trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCairoWin.cpp	2013-06-19 18:17:26 UTC (rev 151743)
@@ -56,8 +56,8 @@
     cairo_font_face_destroy(fontFace);
 }
 
-FontPlatformData::FontPlatformData(cairo_font_face_t* fontFace, float size, bool bold, bool oblique)
-    : m_font(0)
+FontPlatformData::FontPlatformData(HFONT font, cairo_font_face_t* fontFace, float size, bool bold, bool oblique)
+    : m_font(RefCountedGDIHandle<HFONT>::create(font))
     , m_size(size)
     , m_orientation(Horizontal)
     , m_widthVariant(RegularWidth)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to