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

Side by Side Diff: Source/platform/fonts/harfbuzz/HarfBuzzShaper.cpp

Issue 617103003: Replace ENABLE_OPENTYPE_VERTICAL implementation with HarfBuzz (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@removeOpenTypeVertical
Patch Set: Created 6 years, 2 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 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 { 448 {
449 ASSERT_WITH_SECURITY_IMPLICATION(from >= 0); 449 ASSERT_WITH_SECURITY_IMPLICATION(from >= 0);
450 ASSERT_WITH_SECURITY_IMPLICATION(to <= m_run.length()); 450 ASSERT_WITH_SECURITY_IMPLICATION(to <= m_run.length());
451 m_fromIndex = from; 451 m_fromIndex = from;
452 m_toIndex = to; 452 m_toIndex = to;
453 } 453 }
454 454
455 void HarfBuzzShaper::setFontFeatures() 455 void HarfBuzzShaper::setFontFeatures()
456 { 456 {
457 const FontDescription& description = m_font->fontDescription(); 457 const FontDescription& description = m_font->fontDescription();
458 if (description.orientation() == Vertical) {
459 static hb_feature_t vert = { HarfBuzzFace::vertTag, 1, 0, static_cast<un signed>(-1) };
460 static hb_feature_t vrt2 = { HarfBuzzFace::vrt2Tag, 1, 0, static_cast<un signed>(-1) };
461 m_features.append(vert);
462 m_features.append(vrt2);
463 }
464 458
465 static hb_feature_t noKern = { HB_TAG('k', 'e', 'r', 'n'), 0, 0, static_cast <unsigned>(-1) }; 459 static hb_feature_t noKern = { HB_TAG('k', 'e', 'r', 'n'), 0, 0, static_cast <unsigned>(-1) };
466 static hb_feature_t noVkrn = { HB_TAG('v', 'k', 'r', 'n'), 0, 0, static_cast <unsigned>(-1) }; 460 static hb_feature_t noVkrn = { HB_TAG('v', 'k', 'r', 'n'), 0, 0, static_cast <unsigned>(-1) };
467 switch (description.kerning()) { 461 switch (description.kerning()) {
468 case FontDescription::NormalKerning: 462 case FontDescription::NormalKerning:
469 // kern/vkrn are enabled by default 463 // kern/vkrn are enabled by default
470 break; 464 break;
471 case FontDescription::NoneKerning: 465 case FontDescription::NoneKerning:
472 m_features.append(description.orientation() == Vertical ? noVkrn : noKer n); 466 m_features.append(description.orientation() == Vertical ? noVkrn : noKer n);
473 break; 467 break;
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 // A port of hb_icu_script_to_script because harfbuzz on CrOS is built 770 // A port of hb_icu_script_to_script because harfbuzz on CrOS is built
777 // without hb-icu. See http://crbug.com/356929 771 // without hb-icu. See http://crbug.com/356929
778 static inline hb_script_t ICUScriptToHBScript(UScriptCode script) 772 static inline hb_script_t ICUScriptToHBScript(UScriptCode script)
779 { 773 {
780 if (UNLIKELY(script == USCRIPT_INVALID_CODE)) 774 if (UNLIKELY(script == USCRIPT_INVALID_CODE))
781 return HB_SCRIPT_INVALID; 775 return HB_SCRIPT_INVALID;
782 776
783 return hb_script_from_string(uscript_getShortName(script), -1); 777 return hb_script_from_string(uscript_getShortName(script), -1);
784 } 778 }
785 779
786 static inline hb_direction_t TextDirectionToHBDirection(TextDirection dir) 780 static inline hb_direction_t TextDirectionToHBDirection(TextDirection dir, FontO rientation orientation, const SimpleFontData* fontData)
787 { 781 {
788 return dir == RTL ? HB_DIRECTION_RTL : HB_DIRECTION_LTR; 782 hb_direction_t harfBuzzDirection = orientation == Vertical && !fontData->isT extOrientationFallback() ? HB_DIRECTION_TTB : HB_DIRECTION_LTR;
783 return dir == RTL ? HB_DIRECTION_REVERSE(harfBuzzDirection) : harfBuzzDirect ion;
789 } 784 }
790 785
791 786
792 void HarfBuzzShaper::addHarfBuzzRun(unsigned startCharacter, 787 void HarfBuzzShaper::addHarfBuzzRun(unsigned startCharacter,
793 unsigned endCharacter, const SimpleFontData* fontData, 788 unsigned endCharacter, const SimpleFontData* fontData,
794 UScriptCode script) 789 UScriptCode script)
795 { 790 {
796 ASSERT(endCharacter > startCharacter); 791 ASSERT(endCharacter > startCharacter);
797 ASSERT(script != USCRIPT_INVALID_CODE); 792 ASSERT(script != USCRIPT_INVALID_CODE);
798 if (m_fallbackFonts) 793 if (m_fallbackFonts)
799 m_fallbackFonts->add(fontData); 794 m_fallbackFonts->add(fontData);
800 return m_harfBuzzRuns.append(HarfBuzzRun::create(fontData, 795 return m_harfBuzzRuns.append(HarfBuzzRun::create(fontData,
801 startCharacter, endCharacter - startCharacter, 796 startCharacter, endCharacter - startCharacter,
802 TextDirectionToHBDirection(m_run.direction()), 797 TextDirectionToHBDirection(m_run.direction(), m_font->fontDescription(). orientation(), fontData),
803 ICUScriptToHBScript(script))); 798 ICUScriptToHBScript(script)));
804 } 799 }
805 800
806 static const uint16_t* toUint16(const UChar* src) 801 static const uint16_t* toUint16(const UChar* src)
807 { 802 {
808 // FIXME: This relies on undefined behavior however it works on the 803 // FIXME: This relies on undefined behavior however it works on the
809 // current versions of all compilers we care about and avoids making 804 // current versions of all compilers we care about and avoids making
810 // a copy of the string. 805 // a copy of the string.
811 COMPILE_ASSERT(sizeof(UChar) == sizeof(uint16_t), UChar_is_the_same_size_as_ uint16_t); 806 COMPILE_ASSERT(sizeof(UChar) == sizeof(uint16_t), UChar_is_the_same_size_as_ uint16_t);
812 return reinterpret_cast<const uint16_t*>(src); 807 return reinterpret_cast<const uint16_t*>(src);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 uint16_t* glyphToCharacterIndexes = currentRun->glyphToCharacterIndexes(); 896 uint16_t* glyphToCharacterIndexes = currentRun->glyphToCharacterIndexes();
902 float totalAdvance = 0; 897 float totalAdvance = 0;
903 FloatPoint glyphOrigin; 898 FloatPoint glyphOrigin;
904 899
905 // HarfBuzz returns the shaping result in visual order. We need not to flip for RTL. 900 // HarfBuzz returns the shaping result in visual order. We need not to flip for RTL.
906 for (size_t i = 0; i < numGlyphs; ++i) { 901 for (size_t i = 0; i < numGlyphs; ++i) {
907 bool runEnd = i + 1 == numGlyphs; 902 bool runEnd = i + 1 == numGlyphs;
908 uint16_t glyph = glyphInfos[i].codepoint; 903 uint16_t glyph = glyphInfos[i].codepoint;
909 float offsetX = harfBuzzPositionToFloat(glyphPositions[i].x_offset); 904 float offsetX = harfBuzzPositionToFloat(glyphPositions[i].x_offset);
910 float offsetY = -harfBuzzPositionToFloat(glyphPositions[i].y_offset); 905 float offsetY = -harfBuzzPositionToFloat(glyphPositions[i].y_offset);
911 float advance = harfBuzzPositionToFloat(glyphPositions[i].x_advance); 906 // One out of x_advance and y_advance is zero, depending on
907 // whether the buffer direction is horizontal or vertical.
908 float advance = harfBuzzPositionToFloat(glyphPositions[i].x_advance + gl yphPositions[i].y_advance);
912 909
913 unsigned currentCharacterIndex = currentRun->startIndex() + glyphInfos[i ].cluster; 910 unsigned currentCharacterIndex = currentRun->startIndex() + glyphInfos[i ].cluster;
914 bool isClusterEnd = runEnd || glyphInfos[i].cluster != glyphInfos[i + 1] .cluster; 911 bool isClusterEnd = runEnd || glyphInfos[i].cluster != glyphInfos[i + 1] .cluster;
915 float spacing = 0; 912 float spacing = 0;
916 913
917 glyphToCharacterIndexes[i] = glyphInfos[i].cluster; 914 glyphToCharacterIndexes[i] = glyphInfos[i].cluster;
918 915
919 if (isClusterEnd && !Character::treatAsZeroWidthSpace(m_normalizedBuffer [currentCharacterIndex])) 916 if (isClusterEnd && !Character::treatAsZeroWidthSpace(m_normalizedBuffer [currentCharacterIndex]))
920 spacing += m_letterSpacing; 917 spacing += m_letterSpacing;
921 918
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 point.x() + fromX, point.x() + toX, 1142 point.x() + fromX, point.x() + toX,
1146 point.y(), height); 1143 point.y(), height);
1147 } 1144 }
1148 1145
1149 return Font::pixelSnappedSelectionRect( 1146 return Font::pixelSnappedSelectionRect(
1150 point.x() + toX, point.x() + fromX, 1147 point.x() + toX, point.x() + fromX,
1151 point.y(), height); 1148 point.y(), height);
1152 } 1149 }
1153 1150
1154 } // namespace blink 1151 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698