| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2008, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2008, 2010 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2006 Alexey Proskuryakov | 3 * Copyright (C) 2006 Alexey Proskuryakov |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 m_platformData.setupPaint(&m_paint); | 99 m_platformData.setupPaint(&m_paint); |
| 100 m_paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 100 m_paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 101 m_paint.getFontMetrics(&metrics); | 101 m_paint.getFontMetrics(&metrics); |
| 102 SkTypeface* face = m_paint.getTypeface(); | 102 SkTypeface* face = m_paint.getTypeface(); |
| 103 ASSERT(face); | 103 ASSERT(face); |
| 104 | 104 |
| 105 int vdmxAscent = 0, vdmxDescent = 0; | 105 int vdmxAscent = 0, vdmxDescent = 0; |
| 106 bool isVDMXValid = false; | 106 bool isVDMXValid = false; |
| 107 | 107 |
| 108 #if OS(LINUX) || OS(ANDROID) | 108 #if OS(LINUX) || OS(ANDROID) |
| 109 // Manually digging up VDMX metrics is only applicable when bytecode hinting u
sing FreeType. | 109 // Manually digging up VDMX metrics is only applicable when bytecode hinting |
| 110 // With DirectWrite or CoreText, no bytecode hinting is ever done. | 110 // using FreeType. With DirectWrite or CoreText, no bytecode hinting is ever |
| 111 // This code should be pushed into FreeType (hinted font metrics). | 111 // done. This code should be pushed into FreeType (hinted font metrics). |
| 112 static const uint32_t vdmxTag = SkSetFourByteTag('V', 'D', 'M', 'X'); | 112 static const uint32_t vdmxTag = SkSetFourByteTag('V', 'D', 'M', 'X'); |
| 113 int pixelSize = m_platformData.size() + 0.5; | 113 int pixelSize = m_platformData.size() + 0.5; |
| 114 if (!m_paint.isAutohinted() && | 114 if (!m_paint.isAutohinted() && |
| 115 (m_paint.getHinting() == SkPaint::kFull_Hinting || | 115 (m_paint.getHinting() == SkPaint::kFull_Hinting || |
| 116 m_paint.getHinting() == SkPaint::kNormal_Hinting)) { | 116 m_paint.getHinting() == SkPaint::kNormal_Hinting)) { |
| 117 size_t vdmxSize = face->getTableSize(vdmxTag); | 117 size_t vdmxSize = face->getTableSize(vdmxTag); |
| 118 if (vdmxSize && vdmxSize < maxVDMXTableSize) { | 118 if (vdmxSize && vdmxSize < maxVDMXTableSize) { |
| 119 uint8_t* vdmxTable = (uint8_t*)WTF::Partitions::fastMalloc( | 119 uint8_t* vdmxTable = (uint8_t*)WTF::Partitions::fastMalloc( |
| 120 vdmxSize, WTF_HEAP_PROFILER_TYPE_NAME(SimpleFontData)); | 120 vdmxSize, WTF_HEAP_PROFILER_TYPE_NAME(SimpleFontData)); |
| 121 if (vdmxTable && | 121 if (vdmxTable && |
| 122 face->getTableData(vdmxTag, 0, vdmxSize, vdmxTable) == vdmxSize && | 122 face->getTableData(vdmxTag, 0, vdmxSize, vdmxTable) == vdmxSize && |
| 123 parseVDMX(&vdmxAscent, &vdmxDescent, vdmxTable, vdmxSize, pixelSize)) | 123 parseVDMX(&vdmxAscent, &vdmxDescent, vdmxTable, vdmxSize, pixelSize)) |
| 124 isVDMXValid = true; | 124 isVDMXValid = true; |
| 125 WTF::Partitions::fastFree(vdmxTable); | 125 WTF::Partitions::fastFree(vdmxTable); |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 #endif | 128 #endif |
| 129 | 129 |
| 130 float ascent; | 130 float ascent; |
| 131 float descent; | 131 float descent; |
| 132 | 132 |
| 133 // Beware those who step here: This code is designed to match Win32 font | 133 // Beware those who step here: This code is designed to match Win32 font |
| 134 // metrics *exactly* (except the adjustment of ascent/descent on Linux/Android
). | 134 // metrics *exactly* (except the adjustment of ascent/descent on |
| 135 // Linux/Android). |
| 135 if (isVDMXValid) { | 136 if (isVDMXValid) { |
| 136 ascent = vdmxAscent; | 137 ascent = vdmxAscent; |
| 137 descent = -vdmxDescent; | 138 descent = -vdmxDescent; |
| 138 } else { | 139 } else { |
| 139 ascent = SkScalarRoundToInt(-metrics.fAscent); | 140 ascent = SkScalarRoundToInt(-metrics.fAscent); |
| 140 descent = SkScalarRoundToInt(metrics.fDescent); | 141 descent = SkScalarRoundToInt(metrics.fDescent); |
| 141 #if OS(LINUX) || OS(ANDROID) | 142 #if OS(LINUX) || OS(ANDROID) |
| 142 // When subpixel positioning is enabled, if the descent is rounded down, the
descent part | 143 // When subpixel positioning is enabled, if the descent is rounded down, the |
| 143 // of the glyph may be truncated when displayed in a 'overflow: hidden' cont
ainer. | 144 // descent part of the glyph may be truncated when displayed in a 'overflow: |
| 144 // To avoid that, borrow 1 unit from the ascent when possible. | 145 // hidden' container. To avoid that, borrow 1 unit from the ascent when |
| 146 // possible. |
| 145 // FIXME: This can be removed if sub-pixel ascent/descent is supported. | 147 // FIXME: This can be removed if sub-pixel ascent/descent is supported. |
| 146 if (platformData().getFontRenderStyle().useSubpixelPositioning && | 148 if (platformData().getFontRenderStyle().useSubpixelPositioning && |
| 147 descent < SkScalarToFloat(metrics.fDescent) && ascent >= 1) { | 149 descent < SkScalarToFloat(metrics.fDescent) && ascent >= 1) { |
| 148 ++descent; | 150 ++descent; |
| 149 --ascent; | 151 --ascent; |
| 150 } | 152 } |
| 151 #endif | 153 #endif |
| 152 } | 154 } |
| 153 | 155 |
| 154 #if OS(MACOSX) | 156 #if OS(MACOSX) |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 if (glyphs[i]) { | 427 if (glyphs[i]) { |
| 426 pageToFill->setGlyphDataForIndex(offset + i, glyphs[i], this); | 428 pageToFill->setGlyphDataForIndex(offset + i, glyphs[i], this); |
| 427 haveGlyphs = true; | 429 haveGlyphs = true; |
| 428 } | 430 } |
| 429 } | 431 } |
| 430 | 432 |
| 431 return haveGlyphs; | 433 return haveGlyphs; |
| 432 } | 434 } |
| 433 | 435 |
| 434 } // namespace blink | 436 } // namespace blink |
| OLD | NEW |