OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2010, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2010, 2011 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 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 20 matching lines...) Expand all Loading... |
31 #import <ApplicationServices/ApplicationServices.h> | 31 #import <ApplicationServices/ApplicationServices.h> |
32 #import <float.h> | 32 #import <float.h> |
33 #import <unicode/uchar.h> | 33 #import <unicode/uchar.h> |
34 #import "core/platform/SharedBuffer.h" | 34 #import "core/platform/SharedBuffer.h" |
35 #import "core/platform/graphics/Color.h" | 35 #import "core/platform/graphics/Color.h" |
36 #import "core/platform/graphics/FloatRect.h" | 36 #import "core/platform/graphics/FloatRect.h" |
37 #import "core/platform/graphics/Font.h" | 37 #import "core/platform/graphics/Font.h" |
38 #import "core/platform/graphics/FontCache.h" | 38 #import "core/platform/graphics/FontCache.h" |
39 #import "core/platform/graphics/FontDescription.h" | 39 #import "core/platform/graphics/FontDescription.h" |
40 #import "core/platform/mac/BlockExceptions.h" | 40 #import "core/platform/mac/BlockExceptions.h" |
41 #import "core/platform/mac/WebCoreSystemInterface.h" | |
42 #import <wtf/Assertions.h> | 41 #import <wtf/Assertions.h> |
43 #import <wtf/RetainPtr.h> | 42 #import <wtf/RetainPtr.h> |
44 #import <wtf/StdLibExtras.h> | 43 #import <wtf/StdLibExtras.h> |
45 #import <wtf/UnusedParam.h> | 44 #import <wtf/UnusedParam.h> |
46 | 45 |
47 @interface NSFont (WebAppKitSecretAPI) | 46 @interface NSFont (WebAppKitSecretAPI) |
48 - (BOOL)_isFakeFixedPitch; | 47 - (BOOL)_isFakeFixedPitch; |
49 @end | 48 @end |
50 | 49 |
| 50 // The names of these constants were taken from history |
| 51 // /trunk/WebKit/WebCoreSupport.subproj/WebTextRenderer.m@9311. The values |
| 52 // were derived from the assembly of libWebKitSystemInterfaceLeopard.a. |
| 53 enum CGFontRenderingMode { |
| 54 kCGFontRenderingMode1BitPixelAligned = 0x0, |
| 55 kCGFontRenderingModeAntialiasedPixelAligned = 0x1, |
| 56 kCGFontRenderingModeAntialiased = 0xd |
| 57 }; |
| 58 |
| 59 // Forward declare Mac SPIs. |
| 60 extern "C" { |
| 61 // Request for public API: rdar://13803586 |
| 62 bool CGFontGetGlyphAdvancesForStyle(CGFontRef font, CGAffineTransform* transform
, CGFontRenderingMode renderingMode, ATSGlyphRef* glyph, size_t count, CGSize* a
dvance); |
| 63 |
| 64 // Request for public API: rdar://13803619 |
| 65 CTLineRef CTLineCreateWithUniCharProvider(const UniChar* (*provide)(CFIndex stri
ngIndex, CFIndex* charCount, CFDictionaryRef* attributes, void* context), void (
*dispose)(const UniChar* chars, void* context), void* context); |
| 66 } |
| 67 |
| 68 static CGFontRenderingMode cgFontRenderingModeForNSFont(NSFont* font) { |
| 69 if (!font) |
| 70 return kCGFontRenderingModeAntialiasedPixelAligned; |
| 71 |
| 72 switch ([font renderingMode]) { |
| 73 case NSFontIntegerAdvancementsRenderingMode: return kCGFontRenderingMode
1BitPixelAligned; |
| 74 case NSFontAntialiasedIntegerAdvancementsRenderingMode: return kCGFontRe
nderingModeAntialiasedPixelAligned; |
| 75 default: return kCGFontRenderingModeAntialiased; |
| 76 } |
| 77 } |
| 78 |
51 using namespace std; | 79 using namespace std; |
52 | 80 |
53 namespace WebCore { | 81 namespace WebCore { |
54 | 82 |
55 static bool fontHasVerticalGlyphs(CTFontRef ctFont) | 83 static bool fontHasVerticalGlyphs(CTFontRef ctFont) |
56 { | 84 { |
57 // The check doesn't look neat but this is what AppKit does for vertical wri
ting... | 85 // The check doesn't look neat but this is what AppKit does for vertical wri
ting... |
58 RetainPtr<CFArrayRef> tableTags(AdoptCF, CTFontCopyAvailableTables(ctFont, k
CTFontTableOptionNoOptions)); | 86 RetainPtr<CFArrayRef> tableTags(AdoptCF, CTFontCopyAvailableTables(ctFont, k
CTFontTableOptionNoOptions)); |
59 CFIndex numTables = CFArrayGetCount(tableTags.get()); | 87 CFIndex numTables = CFArrayGetCount(tableTags.get()); |
60 for (CFIndex index = 0; index < numTables; ++index) { | 88 for (CFIndex index = 0; index < numTables; ++index) { |
61 CTFontTableTag tag = (CTFontTableTag)(uintptr_t)CFArrayGetValueAtIndex(t
ableTags.get(), index); | 89 CTFontTableTag tag = (CTFontTableTag)(uintptr_t)CFArrayGetValueAtIndex(t
ableTags.get(), index); |
62 if (tag == kCTFontTableVhea || tag == kCTFontTableVORG) | 90 if (tag == kCTFontTableVhea || tag == kCTFontTableVORG) |
63 return true; | 91 return true; |
64 } | 92 } |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const | 414 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const |
387 { | 415 { |
388 CGSize advance = CGSizeZero; | 416 CGSize advance = CGSizeZero; |
389 if (platformData().orientation() == Horizontal || m_isBrokenIdeographFallbac
k) { | 417 if (platformData().orientation() == Horizontal || m_isBrokenIdeographFallbac
k) { |
390 NSFont *font = platformData().font(); | 418 NSFont *font = platformData().font(); |
391 if (font && platformData().isColorBitmapFont()) | 419 if (font && platformData().isColorBitmapFont()) |
392 advance = NSSizeToCGSize([font advancementForGlyph:glyph]); | 420 advance = NSSizeToCGSize([font advancementForGlyph:glyph]); |
393 else { | 421 else { |
394 float pointSize = platformData().m_size; | 422 float pointSize = platformData().m_size; |
395 CGAffineTransform m = CGAffineTransformMakeScale(pointSize, pointSiz
e); | 423 CGAffineTransform m = CGAffineTransformMakeScale(pointSize, pointSiz
e); |
396 if (!WKGetGlyphTransformedAdvances(platformData().cgFont(), font, &m
, &glyph, &advance)) { | 424 if (!CGFontGetGlyphAdvancesForStyle(platformData().cgFont(), &m, cgF
ontRenderingModeForNSFont(font), &glyph, 1, &advance)) { |
397 LOG_ERROR("Unable to cache glyph widths for %@ %f", [font displa
yName], pointSize); | 425 LOG_ERROR("Unable to cache glyph widths for %@ %f", [font displa
yName], pointSize); |
398 advance.width = 0; | 426 advance.width = 0; |
399 } | 427 } |
400 } | 428 } |
401 } else | 429 } else |
402 CTFontGetAdvancesForGlyphs(m_platformData.ctFont(), kCTFontVerticalOrien
tation, &glyph, &advance, 1); | 430 CTFontGetAdvancesForGlyphs(m_platformData.ctFont(), kCTFontVerticalOrien
tation, &glyph, &advance, 1); |
403 | 431 |
404 return advance.width + m_syntheticBoldOffset; | 432 return advance.width + m_syntheticBoldOffset; |
405 } | 433 } |
406 | 434 |
(...skipping 21 matching lines...) Expand all Loading... |
428 if (!m_combiningCharacterSequenceSupport) | 456 if (!m_combiningCharacterSequenceSupport) |
429 m_combiningCharacterSequenceSupport = adoptPtr(new HashMap<String, bool>
); | 457 m_combiningCharacterSequenceSupport = adoptPtr(new HashMap<String, bool>
); |
430 | 458 |
431 WTF::HashMap<String, bool>::AddResult addResult = m_combiningCharacterSequen
ceSupport->add(String(characters, length), false); | 459 WTF::HashMap<String, bool>::AddResult addResult = m_combiningCharacterSequen
ceSupport->add(String(characters, length), false); |
432 if (!addResult.isNewEntry) | 460 if (!addResult.isNewEntry) |
433 return addResult.iterator->value; | 461 return addResult.iterator->value; |
434 | 462 |
435 RetainPtr<CGFontRef> cgFont(AdoptCF, CTFontCopyGraphicsFont(platformData().c
tFont(), 0)); | 463 RetainPtr<CGFontRef> cgFont(AdoptCF, CTFontCopyGraphicsFont(platformData().c
tFont(), 0)); |
436 | 464 |
437 ProviderInfo info = { characters, length, getCFStringAttributes(0, platformD
ata().orientation()) }; | 465 ProviderInfo info = { characters, length, getCFStringAttributes(0, platformD
ata().orientation()) }; |
438 RetainPtr<CTLineRef> line(AdoptCF, WKCreateCTLineWithUniCharProvider(&provid
eStringAndAttributes, 0, &info)); | 466 RetainPtr<CTLineRef> line(AdoptCF, CTLineCreateWithUniCharProvider(&provideS
tringAndAttributes, 0, &info)); |
439 | 467 |
440 CFArrayRef runArray = CTLineGetGlyphRuns(line.get()); | 468 CFArrayRef runArray = CTLineGetGlyphRuns(line.get()); |
441 CFIndex runCount = CFArrayGetCount(runArray); | 469 CFIndex runCount = CFArrayGetCount(runArray); |
442 | 470 |
443 for (CFIndex r = 0; r < runCount; r++) { | 471 for (CFIndex r = 0; r < runCount; r++) { |
444 CTRunRef ctRun = static_cast<CTRunRef>(CFArrayGetValueAtIndex(runArray,
r)); | 472 CTRunRef ctRun = static_cast<CTRunRef>(CFArrayGetValueAtIndex(runArray,
r)); |
445 ASSERT(CFGetTypeID(ctRun) == CTRunGetTypeID()); | 473 ASSERT(CFGetTypeID(ctRun) == CTRunGetTypeID()); |
446 CFDictionaryRef runAttributes = CTRunGetAttributes(ctRun); | 474 CFDictionaryRef runAttributes = CTRunGetAttributes(ctRun); |
447 CTFontRef runFont = static_cast<CTFontRef>(CFDictionaryGetValue(runAttri
butes, kCTFontAttributeName)); | 475 CTFontRef runFont = static_cast<CTFontRef>(CFDictionaryGetValue(runAttri
butes, kCTFontAttributeName)); |
448 RetainPtr<CGFontRef> runCGFont(AdoptCF, CTFontCopyGraphicsFont(runFont,
0)); | 476 RetainPtr<CGFontRef> runCGFont(AdoptCF, CTFontCopyGraphicsFont(runFont,
0)); |
449 if (!CFEqual(runCGFont.get(), cgFont.get())) | 477 if (!CFEqual(runCGFont.get(), cgFont.get())) |
450 return false; | 478 return false; |
451 } | 479 } |
452 | 480 |
453 addResult.iterator->value = true; | 481 addResult.iterator->value = true; |
454 return true; | 482 return true; |
455 } | 483 } |
456 | 484 |
457 } // namespace WebCore | 485 } // namespace WebCore |
OLD | NEW |