OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 Google Inc. All rights reserved. | 2 * Copyright (c) 2012 Google Inc. All rights reserved. |
3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved. | 3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved. |
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 are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * 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 27 matching lines...) Expand all Loading... |
38 #include "platform/fonts/UTF16TextIterator.h" | 38 #include "platform/fonts/UTF16TextIterator.h" |
39 #include "platform/fonts/opentype/OpenTypeCapsSupport.h" | 39 #include "platform/fonts/opentype/OpenTypeCapsSupport.h" |
40 #include "platform/fonts/shaping/CaseMappingHarfBuzzBufferFiller.h" | 40 #include "platform/fonts/shaping/CaseMappingHarfBuzzBufferFiller.h" |
41 #include "platform/fonts/shaping/HarfBuzzFace.h" | 41 #include "platform/fonts/shaping/HarfBuzzFace.h" |
42 #include "platform/fonts/shaping/RunSegmenter.h" | 42 #include "platform/fonts/shaping/RunSegmenter.h" |
43 #include "platform/fonts/shaping/ShapeResultInlineHeaders.h" | 43 #include "platform/fonts/shaping/ShapeResultInlineHeaders.h" |
44 #include "platform/text/Character.h" | 44 #include "platform/text/Character.h" |
45 #include "platform/text/TextBreakIterator.h" | 45 #include "platform/text/TextBreakIterator.h" |
46 #include "wtf/Compiler.h" | 46 #include "wtf/Compiler.h" |
47 #include "wtf/MathExtras.h" | 47 #include "wtf/MathExtras.h" |
| 48 #include "wtf/PtrUtil.h" |
48 #include "wtf/text/Unicode.h" | 49 #include "wtf/text/Unicode.h" |
49 | |
50 #include <algorithm> | 50 #include <algorithm> |
51 #include <hb.h> | 51 #include <hb.h> |
| 52 #include <memory> |
52 #include <unicode/uchar.h> | 53 #include <unicode/uchar.h> |
53 #include <unicode/uscript.h> | 54 #include <unicode/uscript.h> |
54 | 55 |
55 namespace blink { | 56 namespace blink { |
56 | 57 |
57 template<typename T> | 58 template<typename T> |
58 class HarfBuzzScopedPtr { | 59 class HarfBuzzScopedPtr { |
59 STACK_ALLOCATED(); | 60 STACK_ALLOCATED(); |
60 WTF_MAKE_NONCOPYABLE(HarfBuzzScopedPtr); | 61 WTF_MAKE_NONCOPYABLE(HarfBuzzScopedPtr); |
61 public: | 62 public: |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 108 |
108 U16_APPEND(destination, *destinationLength, length, character, error); | 109 U16_APPEND(destination, *destinationLength, length, character, error); |
109 ASSERT_UNUSED(error, !error); | 110 ASSERT_UNUSED(error, !error); |
110 } | 111 } |
111 } | 112 } |
112 | 113 |
113 HarfBuzzShaper::HarfBuzzShaper(const Font* font, const TextRun& run) | 114 HarfBuzzShaper::HarfBuzzShaper(const Font* font, const TextRun& run) |
114 : Shaper(font, run) | 115 : Shaper(font, run) |
115 , m_normalizedBufferLength(0) | 116 , m_normalizedBufferLength(0) |
116 { | 117 { |
117 m_normalizedBuffer = adoptArrayPtr(new UChar[m_textRun.length() + 1]); | 118 m_normalizedBuffer = wrapArrayUnique(new UChar[m_textRun.length() + 1]); |
118 normalizeCharacters(m_textRun, m_textRun.length(), m_normalizedBuffer.get(),
&m_normalizedBufferLength); | 119 normalizeCharacters(m_textRun, m_textRun.length(), m_normalizedBuffer.get(),
&m_normalizedBufferLength); |
119 setFontFeatures(); | 120 setFontFeatures(); |
120 } | 121 } |
121 | 122 |
122 static inline hb_feature_t createFeature(uint8_t c1, uint8_t c2, uint8_t c3, uin
t8_t c4, uint32_t value = 0) | 123 static inline hb_feature_t createFeature(uint8_t c1, uint8_t c2, uint8_t c3, uin
t8_t c4, uint32_t value = 0) |
123 { | 124 { |
124 return { HB_TAG(c1, c2, c3, c4), value, 0 /* start */, static_cast<unsigned>
(-1) /* end */ }; | 125 return { HB_TAG(c1, c2, c3, c4), value, 0 /* start */, static_cast<unsigned>
(-1) /* end */ }; |
125 } | 126 } |
126 | 127 |
127 void HarfBuzzShaper::setFontFeatures() | 128 void HarfBuzzShaper::setFontFeatures() |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 // When we're getting here with the last resort font, we have no other | 461 // When we're getting here with the last resort font, we have no other |
461 // choice than adding boxes to the ShapeResult. | 462 // choice than adding boxes to the ShapeResult. |
462 if ((currentClusterResult == NotDef && numCharacters) || isLastResort) { | 463 if ((currentClusterResult == NotDef && numCharacters) || isLastResort) { |
463 hb_direction_t direction = TextDirectionToHBDirection( | 464 hb_direction_t direction = TextDirectionToHBDirection( |
464 m_textRun.direction(), | 465 m_textRun.direction(), |
465 m_font->getFontDescription().orientation(), currentFont); | 466 m_font->getFontDescription().orientation(), currentFont); |
466 // Here we need to specify glyph positions. | 467 // Here we need to specify glyph positions. |
467 ShapeResult::RunInfo* run = new ShapeResult::RunInfo(currentFont, | 468 ShapeResult::RunInfo* run = new ShapeResult::RunInfo(currentFont, |
468 direction, ICUScriptToHBScript(currentRunScript), | 469 direction, ICUScriptToHBScript(currentRunScript), |
469 startIndex, numGlyphsToInsert, numCharacters); | 470 startIndex, numGlyphsToInsert, numCharacters); |
470 shapeResult->insertRun(adoptPtr(run), lastChangePosition, | 471 shapeResult->insertRun(wrapUnique(run), lastChangePosition, |
471 numGlyphsToInsert, | 472 numGlyphsToInsert, |
472 harfBuzzBuffer); | 473 harfBuzzBuffer); |
473 } | 474 } |
474 lastChangePosition = glyphIndex; | 475 lastChangePosition = glyphIndex; |
475 } | 476 } |
476 return true; | 477 return true; |
477 } | 478 } |
478 | 479 |
479 static inline const SimpleFontData* fontDataAdjustedForOrientation(const SimpleF
ontData* originalFont, | 480 static inline const SimpleFontData* fontDataAdjustedForOrientation(const SimpleF
ontData* originalFont, |
480 FontOrientation runOrientation, | 481 FontOrientation runOrientation, |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 hb_buffer_reset(harfBuzzBuffer.get()); | 675 hb_buffer_reset(harfBuzzBuffer.get()); |
675 } | 676 } |
676 } | 677 } |
677 return result.release(); | 678 return result.release(); |
678 } | 679 } |
679 | 680 |
680 PassRefPtr<ShapeResult> ShapeResult::createForTabulationCharacters(const Font* f
ont, | 681 PassRefPtr<ShapeResult> ShapeResult::createForTabulationCharacters(const Font* f
ont, |
681 const TextRun& textRun, float positionOffset, unsigned count) | 682 const TextRun& textRun, float positionOffset, unsigned count) |
682 { | 683 { |
683 const SimpleFontData* fontData = font->primaryFont(); | 684 const SimpleFontData* fontData = font->primaryFont(); |
684 OwnPtr<ShapeResult::RunInfo> run = adoptPtr(new ShapeResult::RunInfo(fontDat
a, | 685 std::unique_ptr<ShapeResult::RunInfo> run = wrapUnique(new ShapeResult::RunI
nfo(fontData, |
685 // Tab characters are always LTR or RTL, not TTB, even when isVerticalAn
yUpright(). | 686 // Tab characters are always LTR or RTL, not TTB, even when isVerticalAn
yUpright(). |
686 textRun.rtl() ? HB_DIRECTION_RTL : HB_DIRECTION_LTR, | 687 textRun.rtl() ? HB_DIRECTION_RTL : HB_DIRECTION_LTR, |
687 HB_SCRIPT_COMMON, 0, count, count)); | 688 HB_SCRIPT_COMMON, 0, count, count)); |
688 float position = textRun.xPos() + positionOffset; | 689 float position = textRun.xPos() + positionOffset; |
689 float startPosition = position; | 690 float startPosition = position; |
690 for (unsigned i = 0; i < count; i++) { | 691 for (unsigned i = 0; i < count; i++) { |
691 float advance = font->tabWidth(*fontData, textRun.getTabSize(), position
); | 692 float advance = font->tabWidth(*fontData, textRun.getTabSize(), position
); |
692 run->m_glyphData[i].characterIndex = i; | 693 run->m_glyphData[i].characterIndex = i; |
693 run->setGlyphAndPositions(i, fontData->spaceGlyph(), advance, 0, 0); | 694 run->setGlyphAndPositions(i, fontData->spaceGlyph(), advance, 0, 0); |
694 position += advance; | 695 position += advance; |
695 } | 696 } |
696 run->m_width = position - startPosition; | 697 run->m_width = position - startPosition; |
697 | 698 |
698 RefPtr<ShapeResult> result = ShapeResult::create(font, count, textRun.direct
ion()); | 699 RefPtr<ShapeResult> result = ShapeResult::create(font, count, textRun.direct
ion()); |
699 result->m_width = run->m_width; | 700 result->m_width = run->m_width; |
700 result->m_numGlyphs = count; | 701 result->m_numGlyphs = count; |
701 ASSERT(result->m_numGlyphs == count); // no overflow | 702 ASSERT(result->m_numGlyphs == count); // no overflow |
702 result->m_hasVerticalOffsets = fontData->platformData().isVerticalAnyUpright
(); | 703 result->m_hasVerticalOffsets = fontData->platformData().isVerticalAnyUpright
(); |
703 result->m_runs.append(std::move(run)); | 704 result->m_runs.append(std::move(run)); |
704 return result.release(); | 705 return result.release(); |
705 } | 706 } |
706 | 707 |
707 | 708 |
708 } // namespace blink | 709 } // namespace blink |
OLD | NEW |