Home | History | Annotate | Download | only in win
      1 /*
      2  * This file is part of the internal font implementation.  It should not be included by anyone other than
      3  * FontMac.cpp, FontWin.cpp and Font.cpp.
      4  *
      5  * Copyright (C) 2006, 2007, 2008 Apple Inc.
      6  * Copyright (C) 2008 Brent Fulgham
      7  *
      8  * This library is free software; you can redistribute it and/or
      9  * modify it under the terms of the GNU Library General Public
     10  * License as published by the Free Software Foundation; either
     11  * version 2 of the License, or (at your option) any later version.
     12  *
     13  * This library is distributed in the hope that it will be useful,
     14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16  * Library General Public License for more details.
     17  *
     18  * You should have received a copy of the GNU Library General Public License
     19  * along with this library; see the file COPYING.LIB.  If not, write to
     20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     21  * Boston, MA 02110-1301, USA.
     22  *
     23  */
     24 
     25 #include "config.h"
     26 #include "FontPlatformData.h"
     27 
     28 #include "PlatformString.h"
     29 #include <wtf/HashMap.h>
     30 #include <wtf/RetainPtr.h>
     31 #include <wtf/Vector.h>
     32 #include <wtf/text/StringHash.h>
     33 
     34 using std::min;
     35 
     36 namespace WebCore {
     37 
     38 FontPlatformData::FontPlatformData(HFONT font, float size, bool bold, bool oblique, bool useGDI)
     39     : m_font(RefCountedGDIHandle<HFONT>::create(font))
     40     , m_size(size)
     41     , m_orientation(Horizontal)
     42     , m_textOrientation(TextOrientationVerticalRight)
     43     , m_widthVariant(RegularWidth)
     44 #if USE(CG)
     45     , m_cgFont(0)
     46 #elif USE(CAIRO)
     47     , m_scaledFont(0)
     48 #endif
     49     , m_isColorBitmapFont(false)
     50     , m_syntheticBold(bold)
     51     , m_syntheticOblique(oblique)
     52     , m_useGDI(useGDI)
     53 {
     54     HDC hdc = GetDC(0);
     55     SaveDC(hdc);
     56 
     57     SelectObject(hdc, font);
     58     UINT bufferSize = GetOutlineTextMetrics(hdc, 0, NULL);
     59 
     60     ASSERT_WITH_MESSAGE(bufferSize, "Bitmap fonts not supported with CoreGraphics.");
     61 
     62     if (bufferSize) {
     63         OUTLINETEXTMETRICW* metrics = (OUTLINETEXTMETRICW*)malloc(bufferSize);
     64 
     65         GetOutlineTextMetricsW(hdc, bufferSize, metrics);
     66         WCHAR* faceName = (WCHAR*)((uintptr_t)metrics + (uintptr_t)metrics->otmpFaceName);
     67 
     68         platformDataInit(font, size, hdc, faceName);
     69 
     70         free(metrics);
     71     }
     72 
     73     RestoreDC(hdc, -1);
     74     ReleaseDC(0, hdc);
     75 }
     76 
     77 #ifndef NDEBUG
     78 String FontPlatformData::description() const
     79 {
     80     return String();
     81 }
     82 #endif
     83 
     84 }
     85