| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of the internal font implementation. | 2 * This file is part of the internal font implementation. |
| 3 * | 3 * |
| 4 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. | 4 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. |
| 5 * Copyright (c) 2010 Google Inc. All rights reserved. | 5 * Copyright (c) 2010 Google Inc. All rights reserved. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 values, | 66 values, |
| 67 WTF_ARRAY_LENGTH(ke
ys), | 67 WTF_ARRAY_LENGTH(ke
ys), |
| 68 &kCFTypeDictionaryK
eyCallBacks, | 68 &kCFTypeDictionaryK
eyCallBacks, |
| 69 &kCFTypeDictionaryV
alueCallBacks)); | 69 &kCFTypeDictionaryV
alueCallBacks)); |
| 70 | 70 |
| 71 descriptor = CTFontDescriptorCreateWithAttributes(attributes.get()); | 71 descriptor = CTFontDescriptorCreateWithAttributes(attributes.get()); |
| 72 | 72 |
| 73 return descriptor; | 73 return descriptor; |
| 74 } | 74 } |
| 75 | 75 |
| 76 static PassRefPtr<SkTypeface> loadFromBrowserProcess(NSFont* nsFont, float textS
ize) | 76 static sk_sp<SkTypeface> loadFromBrowserProcess(NSFont* nsFont, float textSize) |
| 77 { | 77 { |
| 78 // Send cross-process request to load font. | 78 // Send cross-process request to load font. |
| 79 WebSandboxSupport* sandboxSupport = Platform::current()->sandboxSupport(); | 79 WebSandboxSupport* sandboxSupport = Platform::current()->sandboxSupport(); |
| 80 if (!sandboxSupport) { | 80 if (!sandboxSupport) { |
| 81 // This function should only be called in response to an error loading a | 81 // This function should only be called in response to an error loading a |
| 82 // font due to being blocked by the sandbox. | 82 // font due to being blocked by the sandbox. |
| 83 // This by definition shouldn't happen if there is no sandbox support. | 83 // This by definition shouldn't happen if there is no sandbox support. |
| 84 ASSERT_NOT_REACHED(); | 84 ASSERT_NOT_REACHED(); |
| 85 return nullptr; | 85 return nullptr; |
| 86 } | 86 } |
| 87 | 87 |
| 88 CGFontRef loadedCgFont; | 88 CGFontRef loadedCgFont; |
| 89 uint32_t fontID; | 89 uint32_t fontID; |
| 90 if (!sandboxSupport->loadFont(nsFont, &loadedCgFont, &fontID)) { | 90 if (!sandboxSupport->loadFont(nsFont, &loadedCgFont, &fontID)) { |
| 91 // TODO crbug.com/461279: Make this appear in the inspector console? | 91 // TODO crbug.com/461279: Make this appear in the inspector console? |
| 92 DLOG(ERROR) << "Loading user font \"" << [[nsFont familyName] UTF8String
] << "\" from non system location failed. Corrupt or missing font file?"; | 92 DLOG(ERROR) << "Loading user font \"" << [[nsFont familyName] UTF8String
] << "\" from non system location failed. Corrupt or missing font file?"; |
| 93 return nullptr; | 93 return nullptr; |
| 94 } | 94 } |
| 95 RetainPtr<CGFontRef> cgFont(AdoptCF, loadedCgFont); | 95 RetainPtr<CGFontRef> cgFont(AdoptCF, loadedCgFont); |
| 96 RetainPtr<CTFontRef> ctFont(AdoptCF, CTFontCreateWithGraphicsFont(cgFont.get
(), textSize, 0, cascadeToLastResortFontDescriptor())); | 96 RetainPtr<CTFontRef> ctFont(AdoptCF, CTFontCreateWithGraphicsFont(cgFont.get
(), textSize, 0, cascadeToLastResortFontDescriptor())); |
| 97 PassRefPtr<SkTypeface> returnFont = adoptRef(SkCreateTypefaceFromCTFont(ctFo
nt.get(), cgFont.get())); | 97 sk_sp<SkTypeface> returnFont(SkCreateTypefaceFromCTFont(ctFont.get(), cgFont
.get())); |
| 98 | 98 |
| 99 if (!returnFont.get()) | 99 if (!returnFont.get()) |
| 100 // TODO crbug.com/461279: Make this appear in the inspector console? | 100 // TODO crbug.com/461279: Make this appear in the inspector console? |
| 101 DLOG(ERROR) << "Instantiating SkTypeface from user font failed for font
family \"" << [[nsFont familyName] UTF8String] << "\"."; | 101 DLOG(ERROR) << "Instantiating SkTypeface from user font failed for font
family \"" << [[nsFont familyName] UTF8String] << "\"."; |
| 102 return returnFont; | 102 return returnFont; |
| 103 } | 103 } |
| 104 | 104 |
| 105 void FontPlatformData::setupPaint(SkPaint* paint, float, const Font* font) const | 105 void FontPlatformData::setupPaint(SkPaint* paint, float, const Font* font) const |
| 106 { | 106 { |
| 107 bool shouldSmoothFonts = true; | 107 bool shouldSmoothFonts = true; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 126 | 126 |
| 127 if (LayoutTestSupport::isRunningLayoutTest()) { | 127 if (LayoutTestSupport::isRunningLayoutTest()) { |
| 128 shouldSmoothFonts = false; | 128 shouldSmoothFonts = false; |
| 129 shouldAntialias = shouldAntialias && LayoutTestSupport::isFontAntialiasi
ngEnabledForTest(); | 129 shouldAntialias = shouldAntialias && LayoutTestSupport::isFontAntialiasi
ngEnabledForTest(); |
| 130 } | 130 } |
| 131 | 131 |
| 132 paint->setAntiAlias(shouldAntialias); | 132 paint->setAntiAlias(shouldAntialias); |
| 133 paint->setEmbeddedBitmapText(false); | 133 paint->setEmbeddedBitmapText(false); |
| 134 const float ts = m_textSize >= 0 ? m_textSize : 12; | 134 const float ts = m_textSize >= 0 ? m_textSize : 12; |
| 135 paint->setTextSize(SkFloatToScalar(ts)); | 135 paint->setTextSize(SkFloatToScalar(ts)); |
| 136 paint->setTypeface(toSkSp(m_typeface)); | 136 paint->setTypeface(m_typeface); |
| 137 paint->setFakeBoldText(m_syntheticBold); | 137 paint->setFakeBoldText(m_syntheticBold); |
| 138 paint->setTextSkewX(m_syntheticItalic ? -SK_Scalar1 / 4 : 0); | 138 paint->setTextSkewX(m_syntheticItalic ? -SK_Scalar1 / 4 : 0); |
| 139 paint->setLCDRenderText(shouldSmoothFonts); | 139 paint->setLCDRenderText(shouldSmoothFonts); |
| 140 paint->setSubpixelText(true); | 140 paint->setSubpixelText(true); |
| 141 | 141 |
| 142 // When rendering using CoreGraphics, disable hinting when webkit-font-smoot
hing:antialiased or | 142 // When rendering using CoreGraphics, disable hinting when webkit-font-smoot
hing:antialiased or |
| 143 // text-rendering:geometricPrecision is used. | 143 // text-rendering:geometricPrecision is used. |
| 144 // See crbug.com/152304 | 144 // See crbug.com/152304 |
| 145 if (font && (font->getFontDescription().fontSmoothing() == Antialiased || fo
nt->getFontDescription().textRendering() == GeometricPrecision)) | 145 if (font && (font->getFontDescription().fontSmoothing() == Antialiased || fo
nt->getFontDescription().textRendering() == GeometricPrecision)) |
| 146 paint->setHinting(SkPaint::kNo_Hinting); | 146 paint->setHinting(SkPaint::kNo_Hinting); |
| 147 } | 147 } |
| 148 | 148 |
| 149 FontPlatformData::FontPlatformData(NSFont *nsFont, float size, bool syntheticBol
d, bool syntheticItalic, FontOrientation orientation) | 149 FontPlatformData::FontPlatformData(NSFont *nsFont, float size, bool syntheticBol
d, bool syntheticItalic, FontOrientation orientation) |
| 150 : m_textSize(size) | 150 : m_textSize(size) |
| 151 , m_syntheticBold(syntheticBold) | 151 , m_syntheticBold(syntheticBold) |
| 152 , m_syntheticItalic(syntheticItalic) | 152 , m_syntheticItalic(syntheticItalic) |
| 153 , m_orientation(orientation) | 153 , m_orientation(orientation) |
| 154 , m_isHashTableDeletedValue(false) | 154 , m_isHashTableDeletedValue(false) |
| 155 { | 155 { |
| 156 DCHECK(nsFont); | 156 DCHECK(nsFont); |
| 157 if (canLoadInProcess(nsFont)) { | 157 if (canLoadInProcess(nsFont)) { |
| 158 m_typeface = adoptRef(SkCreateTypefaceFromCTFont(toCTFontRef(nsFont))); | 158 m_typeface.reset(SkCreateTypefaceFromCTFont(toCTFontRef(nsFont))); |
| 159 } else { | 159 } else { |
| 160 // In process loading fails for cases where third party font manager sof
tware | 160 // In process loading fails for cases where third party font manager sof
tware |
| 161 // registers fonts in non system locations such as /Library/Fonts | 161 // registers fonts in non system locations such as /Library/Fonts |
| 162 // and ~/Library Fonts, see crbug.com/72727 or crbug.com/108645. | 162 // and ~/Library Fonts, see crbug.com/72727 or crbug.com/108645. |
| 163 m_typeface = loadFromBrowserProcess(nsFont, size); | 163 m_typeface = loadFromBrowserProcess(nsFont, size); |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 | 166 |
| 167 } // namespace blink | 167 } // namespace blink |
| OLD | NEW |