| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * | |
| 8 * 1. Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | |
| 11 * notice, this list of conditions and the following disclaimer in the | |
| 12 * documentation and/or other materials provided with the distribution. | |
| 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | |
| 14 * its contributors may be used to endorse or promote products derived | |
| 15 * from this software without specific prior written permission. | |
| 16 * | |
| 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
| 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
| 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 27 */ | |
| 28 | |
| 29 #include "config.h" | |
| 30 #include "SimpleFontData.h" | |
| 31 | |
| 32 #include "FloatRect.h" | |
| 33 #include "Font.h" | |
| 34 #include "FontCache.h" | |
| 35 #include "FontDescription.h" | |
| 36 #include "HWndDC.h" | |
| 37 #include <ApplicationServices/ApplicationServices.h> | |
| 38 #include <WebKitSystemInterface/WebKitSystemInterface.h> | |
| 39 #include <mlang.h> | |
| 40 #include <unicode/uchar.h> | |
| 41 #include <unicode/unorm.h> | |
| 42 #include <winsock2.h> | |
| 43 #include <wtf/MathExtras.h> | |
| 44 #include <wtf/RetainPtr.h> | |
| 45 #include <wtf/text/WTFString.h> | |
| 46 | |
| 47 namespace WebCore { | |
| 48 | |
| 49 using namespace std; | |
| 50 | |
| 51 void SimpleFontData::platformInit() | |
| 52 { | |
| 53 m_syntheticBoldOffset = m_platformData.syntheticBold() ? 1.0f : 0.f; | |
| 54 m_scriptCache = 0; | |
| 55 m_scriptFontProperties = 0; | |
| 56 m_isSystemFont = false; | |
| 57 | |
| 58 if (m_platformData.useGDI()) | |
| 59 return initGDIFont(); | |
| 60 | |
| 61 CGFontRef font = m_platformData.cgFont(); | |
| 62 int iAscent = CGFontGetAscent(font); | |
| 63 int iDescent = CGFontGetDescent(font); | |
| 64 int iLineGap = CGFontGetLeading(font); | |
| 65 unsigned unitsPerEm = CGFontGetUnitsPerEm(font); | |
| 66 float pointSize = m_platformData.size(); | |
| 67 float fAscent = scaleEmToUnits(iAscent, unitsPerEm) * pointSize; | |
| 68 float fDescent = -scaleEmToUnits(iDescent, unitsPerEm) * pointSize; | |
| 69 float fLineGap = scaleEmToUnits(iLineGap, unitsPerEm) * pointSize; | |
| 70 | |
| 71 if (!isCustomFont()) { | |
| 72 HWndDC dc(0); | |
| 73 HGDIOBJ oldFont = SelectObject(dc, m_platformData.hfont()); | |
| 74 int faceLength = GetTextFace(dc, 0, 0); | |
| 75 Vector<WCHAR> faceName(faceLength); | |
| 76 GetTextFace(dc, faceLength, faceName.data()); | |
| 77 m_isSystemFont = !wcscmp(faceName.data(), L"Lucida Grande"); | |
| 78 SelectObject(dc, oldFont); | |
| 79 | |
| 80 fAscent = ascentConsideringMacAscentHack(faceName.data(), fAscent, fDesc
ent); | |
| 81 } | |
| 82 | |
| 83 m_fontMetrics.setAscent(fAscent); | |
| 84 m_fontMetrics.setDescent(fDescent); | |
| 85 m_fontMetrics.setLineGap(fLineGap); | |
| 86 m_fontMetrics.setLineSpacing(lroundf(fAscent) + lroundf(fDescent) + lroundf(
fLineGap)); | |
| 87 | |
| 88 GlyphPage* glyphPageZero = GlyphPageTreeNode::getRootChild(this, 0)->page(); | |
| 89 Glyph xGlyph = glyphPageZero ? glyphPageZero->glyphDataForCharacter('x').gly
ph : 0; | |
| 90 if (xGlyph) { | |
| 91 // Measure the actual character "x", since it's possible for it to exten
d below the baseline, and we need the | |
| 92 // reported x-height to only include the portion of the glyph that is ab
ove the baseline. | |
| 93 CGRect xBox; | |
| 94 CGFontGetGlyphBBoxes(font, &xGlyph, 1, &xBox); | |
| 95 m_fontMetrics.setXHeight(scaleEmToUnits(CGRectGetMaxY(xBox), unitsPerEm)
* pointSize); | |
| 96 } else { | |
| 97 int iXHeight = CGFontGetXHeight(font); | |
| 98 m_fontMetrics.setXHeight(scaleEmToUnits(iXHeight, unitsPerEm) * pointSiz
e); | |
| 99 } | |
| 100 | |
| 101 m_fontMetrics.setUnitsPerEm(unitsPerEm); | |
| 102 } | |
| 103 | |
| 104 FloatRect SimpleFontData::platformBoundsForGlyph(Glyph glyph) const | |
| 105 { | |
| 106 if (!platformData().size()) | |
| 107 return FloatRect(); | |
| 108 | |
| 109 if (m_platformData.useGDI()) | |
| 110 return boundsForGDIGlyph(glyph); | |
| 111 | |
| 112 CGRect box; | |
| 113 CGFontGetGlyphBBoxes(m_platformData.cgFont(), &glyph, 1, &box); | |
| 114 float pointSize = m_platformData.size(); | |
| 115 CGFloat scale = pointSize / fontMetrics().unitsPerEm(); | |
| 116 FloatRect boundingBox = CGRectApplyAffineTransform(box, CGAffineTransformMak
eScale(scale, -scale)); | |
| 117 if (m_syntheticBoldOffset) | |
| 118 boundingBox.setWidth(boundingBox.width() + m_syntheticBoldOffset); | |
| 119 | |
| 120 return boundingBox; | |
| 121 } | |
| 122 | |
| 123 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const | |
| 124 { | |
| 125 if (!platformData().size()) | |
| 126 return 0; | |
| 127 | |
| 128 if (m_platformData.useGDI()) | |
| 129 return widthForGDIGlyph(glyph); | |
| 130 | |
| 131 CGFontRef font = m_platformData.cgFont(); | |
| 132 float pointSize = m_platformData.size(); | |
| 133 CGSize advance; | |
| 134 CGAffineTransform m = CGAffineTransformMakeScale(pointSize, pointSize); | |
| 135 | |
| 136 // FIXME: Need to add real support for printer fonts. | |
| 137 bool isPrinterFont = false; | |
| 138 wkGetGlyphAdvances(font, m, m_isSystemFont, isPrinterFont, glyph, advance); | |
| 139 | |
| 140 return advance.width + m_syntheticBoldOffset; | |
| 141 } | |
| 142 | |
| 143 } | |
| OLD | NEW |