Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(959)

Side by Side Diff: third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzShaper.cpp

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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"
49 #include "wtf/text/Unicode.h" 48 #include "wtf/text/Unicode.h"
49
50 #include <algorithm> 50 #include <algorithm>
51 #include <hb.h> 51 #include <hb.h>
52 #include <memory>
53 #include <unicode/uchar.h> 52 #include <unicode/uchar.h>
54 #include <unicode/uscript.h> 53 #include <unicode/uscript.h>
55 54
56 namespace blink { 55 namespace blink {
57 56
58 template<typename T> 57 template<typename T>
59 class HarfBuzzScopedPtr { 58 class HarfBuzzScopedPtr {
60 STACK_ALLOCATED(); 59 STACK_ALLOCATED();
61 WTF_MAKE_NONCOPYABLE(HarfBuzzScopedPtr); 60 WTF_MAKE_NONCOPYABLE(HarfBuzzScopedPtr);
62 public: 61 public:
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 107
109 U16_APPEND(destination, *destinationLength, length, character, error); 108 U16_APPEND(destination, *destinationLength, length, character, error);
110 ASSERT_UNUSED(error, !error); 109 ASSERT_UNUSED(error, !error);
111 } 110 }
112 } 111 }
113 112
114 HarfBuzzShaper::HarfBuzzShaper(const Font* font, const TextRun& run) 113 HarfBuzzShaper::HarfBuzzShaper(const Font* font, const TextRun& run)
115 : Shaper(font, run) 114 : Shaper(font, run)
116 , m_normalizedBufferLength(0) 115 , m_normalizedBufferLength(0)
117 { 116 {
118 m_normalizedBuffer = wrapArrayUnique(new UChar[m_textRun.length() + 1]); 117 m_normalizedBuffer = adoptArrayPtr(new UChar[m_textRun.length() + 1]);
119 normalizeCharacters(m_textRun, m_textRun.length(), m_normalizedBuffer.get(), &m_normalizedBufferLength); 118 normalizeCharacters(m_textRun, m_textRun.length(), m_normalizedBuffer.get(), &m_normalizedBufferLength);
120 setFontFeatures(); 119 setFontFeatures();
121 } 120 }
122 121
123 static inline hb_feature_t createFeature(uint8_t c1, uint8_t c2, uint8_t c3, uin t8_t c4, uint32_t value = 0) 122 static inline hb_feature_t createFeature(uint8_t c1, uint8_t c2, uint8_t c3, uin t8_t c4, uint32_t value = 0)
124 { 123 {
125 return { HB_TAG(c1, c2, c3, c4), value, 0 /* start */, static_cast<unsigned> (-1) /* end */ }; 124 return { HB_TAG(c1, c2, c3, c4), value, 0 /* start */, static_cast<unsigned> (-1) /* end */ };
126 } 125 }
127 126
128 void HarfBuzzShaper::setFontFeatures() 127 void HarfBuzzShaper::setFontFeatures()
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 // When we're getting here with the last resort font, we have no other 460 // When we're getting here with the last resort font, we have no other
462 // choice than adding boxes to the ShapeResult. 461 // choice than adding boxes to the ShapeResult.
463 if ((currentClusterResult == NotDef && numCharacters) || isLastResort) { 462 if ((currentClusterResult == NotDef && numCharacters) || isLastResort) {
464 hb_direction_t direction = TextDirectionToHBDirection( 463 hb_direction_t direction = TextDirectionToHBDirection(
465 m_textRun.direction(), 464 m_textRun.direction(),
466 m_font->getFontDescription().orientation(), currentFont); 465 m_font->getFontDescription().orientation(), currentFont);
467 // Here we need to specify glyph positions. 466 // Here we need to specify glyph positions.
468 ShapeResult::RunInfo* run = new ShapeResult::RunInfo(currentFont, 467 ShapeResult::RunInfo* run = new ShapeResult::RunInfo(currentFont,
469 direction, ICUScriptToHBScript(currentRunScript), 468 direction, ICUScriptToHBScript(currentRunScript),
470 startIndex, numGlyphsToInsert, numCharacters); 469 startIndex, numGlyphsToInsert, numCharacters);
471 shapeResult->insertRun(wrapUnique(run), lastChangePosition, 470 shapeResult->insertRun(adoptPtr(run), lastChangePosition,
472 numGlyphsToInsert, 471 numGlyphsToInsert,
473 harfBuzzBuffer); 472 harfBuzzBuffer);
474 } 473 }
475 lastChangePosition = glyphIndex; 474 lastChangePosition = glyphIndex;
476 } 475 }
477 return true; 476 return true;
478 } 477 }
479 478
480 static inline const SimpleFontData* fontDataAdjustedForOrientation(const SimpleF ontData* originalFont, 479 static inline const SimpleFontData* fontDataAdjustedForOrientation(const SimpleF ontData* originalFont,
481 FontOrientation runOrientation, 480 FontOrientation runOrientation,
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 hb_buffer_reset(harfBuzzBuffer.get()); 674 hb_buffer_reset(harfBuzzBuffer.get());
676 } 675 }
677 } 676 }
678 return result.release(); 677 return result.release();
679 } 678 }
680 679
681 PassRefPtr<ShapeResult> ShapeResult::createForTabulationCharacters(const Font* f ont, 680 PassRefPtr<ShapeResult> ShapeResult::createForTabulationCharacters(const Font* f ont,
682 const TextRun& textRun, float positionOffset, unsigned count) 681 const TextRun& textRun, float positionOffset, unsigned count)
683 { 682 {
684 const SimpleFontData* fontData = font->primaryFont(); 683 const SimpleFontData* fontData = font->primaryFont();
685 std::unique_ptr<ShapeResult::RunInfo> run = wrapUnique(new ShapeResult::RunI nfo(fontData, 684 OwnPtr<ShapeResult::RunInfo> run = adoptPtr(new ShapeResult::RunInfo(fontDat a,
686 // Tab characters are always LTR or RTL, not TTB, even when isVerticalAn yUpright(). 685 // Tab characters are always LTR or RTL, not TTB, even when isVerticalAn yUpright().
687 textRun.rtl() ? HB_DIRECTION_RTL : HB_DIRECTION_LTR, 686 textRun.rtl() ? HB_DIRECTION_RTL : HB_DIRECTION_LTR,
688 HB_SCRIPT_COMMON, 0, count, count)); 687 HB_SCRIPT_COMMON, 0, count, count));
689 float position = textRun.xPos() + positionOffset; 688 float position = textRun.xPos() + positionOffset;
690 float startPosition = position; 689 float startPosition = position;
691 for (unsigned i = 0; i < count; i++) { 690 for (unsigned i = 0; i < count; i++) {
692 float advance = font->tabWidth(*fontData, textRun.getTabSize(), position ); 691 float advance = font->tabWidth(*fontData, textRun.getTabSize(), position );
693 run->m_glyphData[i].characterIndex = i; 692 run->m_glyphData[i].characterIndex = i;
694 run->setGlyphAndPositions(i, fontData->spaceGlyph(), advance, 0, 0); 693 run->setGlyphAndPositions(i, fontData->spaceGlyph(), advance, 0, 0);
695 position += advance; 694 position += advance;
696 } 695 }
697 run->m_width = position - startPosition; 696 run->m_width = position - startPosition;
698 697
699 RefPtr<ShapeResult> result = ShapeResult::create(font, count, textRun.direct ion()); 698 RefPtr<ShapeResult> result = ShapeResult::create(font, count, textRun.direct ion());
700 result->m_width = run->m_width; 699 result->m_width = run->m_width;
701 result->m_numGlyphs = count; 700 result->m_numGlyphs = count;
702 ASSERT(result->m_numGlyphs == count); // no overflow 701 ASSERT(result->m_numGlyphs == count); // no overflow
703 result->m_hasVerticalOffsets = fontData->platformData().isVerticalAnyUpright (); 702 result->m_hasVerticalOffsets = fontData->platformData().isVerticalAnyUpright ();
704 result->m_runs.append(std::move(run)); 703 result->m_runs.append(std::move(run));
705 return result.release(); 704 return result.release();
706 } 705 }
707 706
708 707
709 } // namespace blink 708 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698