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

Side by Side Diff: Source/core/platform/graphics/harfbuzz/HarfBuzzShaper.cpp

Issue 69513002: Implement TrueType kerning support for HarfBuzz text path. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: don't remove empty line at the end of TextExpectations Created 7 years, 1 month 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 * 4 *
4 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
6 * met: 7 * met:
7 * 8 *
8 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 11 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer 12 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 13 * in the documentation and/or other materials provided with the
(...skipping 29 matching lines...) Expand all
42 #include "wtf/Vector.h" 43 #include "wtf/Vector.h"
43 #include <unicode/normlzr.h> 44 #include <unicode/normlzr.h>
44 #include <unicode/uchar.h> 45 #include <unicode/uchar.h>
45 46
46 #include <list> 47 #include <list>
47 #include <map> 48 #include <map>
48 #include <string> 49 #include <string>
49 50
50 namespace WebCore { 51 namespace WebCore {
51 52
53 const hb_tag_t cligTag = HB_TAG('c', 'l', 'i', 'g');
54 const hb_tag_t dligTag = HB_TAG('d', 'l', 'i', 'g');
55 const hb_tag_t hligTag = HB_TAG('h', 'l', 'i', 'g');
56 const hb_tag_t kernTag = HB_TAG('k', 'e', 'r', 'n');
57 const hb_tag_t ligaTag = HB_TAG('l', 'i', 'g', 'a');
58
52 template<typename T> 59 template<typename T>
53 class HarfBuzzScopedPtr { 60 class HarfBuzzScopedPtr {
54 public: 61 public:
55 typedef void (*DestroyFunction)(T*); 62 typedef void (*DestroyFunction)(T*);
56 63
57 HarfBuzzScopedPtr(T* ptr, DestroyFunction destroy) 64 HarfBuzzScopedPtr(T* ptr, DestroyFunction destroy)
58 : m_ptr(ptr) 65 : m_ptr(ptr)
59 , m_destroy(destroy) 66 , m_destroy(destroy)
60 { 67 {
61 ASSERT(m_destroy); 68 ASSERT(m_destroy);
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 void HarfBuzzShaper::setFontFeatures() 508 void HarfBuzzShaper::setFontFeatures()
502 { 509 {
503 const FontDescription& description = m_font->fontDescription(); 510 const FontDescription& description = m_font->fontDescription();
504 if (description.orientation() == Vertical) { 511 if (description.orientation() == Vertical) {
505 static hb_feature_t vert = { HarfBuzzFace::vertTag, 1, 0, static_cast<un signed>(-1) }; 512 static hb_feature_t vert = { HarfBuzzFace::vertTag, 1, 0, static_cast<un signed>(-1) };
506 static hb_feature_t vrt2 = { HarfBuzzFace::vrt2Tag, 1, 0, static_cast<un signed>(-1) }; 513 static hb_feature_t vrt2 = { HarfBuzzFace::vrt2Tag, 1, 0, static_cast<un signed>(-1) };
507 m_features.append(vert); 514 m_features.append(vert);
508 m_features.append(vrt2); 515 m_features.append(vrt2);
509 } 516 }
510 517
518 static hb_feature_t kern = { kernTag, 1, 0, static_cast<unsigned>(-1) };
519 static hb_feature_t noKern = { kernTag, 0, 0, static_cast<unsigned>(-1) };
520 if (!(m_font->typesettingFeatures() & Kerning)) {
521 m_features.append(noKern);
522 } else {
523 switch (description.kerning()) {
524 case FontDescription::NormalKerning:
525 m_features.append(kern);
526 break;
527 case FontDescription::NoneKerning:
528 m_features.append(noKern);
529 break;
530 case FontDescription::AutoKerning:
531 break;
532 }
533 }
534
535 static hb_feature_t liga = { ligaTag, 1, 0, static_cast<unsigned>(-1) };
536 static hb_feature_t noLiga = { ligaTag, 0, 0, static_cast<unsigned>(-1) };
537 static hb_feature_t clig = { cligTag, 1, 0, static_cast<unsigned>(-1) };
538 static hb_feature_t noClig = { cligTag, 0, 0, static_cast<unsigned>(-1) };
539 static hb_feature_t dlig = { dligTag, 1, 0, static_cast<unsigned>(-1) };
540 static hb_feature_t noDlig = { dligTag, 0, 0, static_cast<unsigned>(-1) };
541 static hb_feature_t hlig = { hligTag, 1, 0, static_cast<unsigned>(-1) };
542 static hb_feature_t noHlig = { hligTag, 0, 0, static_cast<unsigned>(-1) };
543 if (!(m_font->typesettingFeatures() & Ligatures)) {
544 m_features.append(noLiga);
545 m_features.append(noClig);
546 m_features.append(noDlig);
547 m_features.append(noHlig);
548 } else {
549 switch (description.commonLigaturesState()) {
550 case FontDescription::DisabledLigaturesState:
551 m_features.append(noLiga);
552 m_features.append(noClig);
553 break;
554 case FontDescription::EnabledLigaturesState:
555 m_features.append(liga);
behdad_google 2013/11/15 16:26:35 Don't append features that are enabled by default.
556 m_features.append(clig);
557 break;
558 case FontDescription::NormalLigaturesState:
559 break;
560 }
561 switch (description.discretionaryLigaturesState()) {
562 case FontDescription::DisabledLigaturesState:
563 m_features.append(noDlig);
564 break;
565 case FontDescription::EnabledLigaturesState:
566 m_features.append(dlig);
567 break;
568 case FontDescription::NormalLigaturesState:
569 break;
570 }
571 switch (description.historicalLigaturesState()) {
572 case FontDescription::DisabledLigaturesState:
573 m_features.append(noHlig);
574 break;
575 case FontDescription::EnabledLigaturesState:
576 m_features.append(hlig);
577 break;
578 case FontDescription::NormalLigaturesState:
579 break;
580 }
581 }
582
511 FontFeatureSettings* settings = description.featureSettings(); 583 FontFeatureSettings* settings = description.featureSettings();
512 if (!settings) 584 if (!settings)
513 return; 585 return;
514 586
515 unsigned numFeatures = settings->size(); 587 unsigned numFeatures = settings->size();
516 for (unsigned i = 0; i < numFeatures; ++i) { 588 for (unsigned i = 0; i < numFeatures; ++i) {
517 hb_feature_t feature; 589 hb_feature_t feature;
518 String tag = settings->at(i).tag(); 590 String tag = settings->at(i).tag();
519 feature.tag = HB_TAG(tag[0], tag[1], tag[2], tag[3]); 591 feature.tag = HB_TAG(tag[0], tag[1], tag[2], tag[3]);
520 feature.value = settings->at(i).value(); 592 feature.value = settings->at(i).value();
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 currentFontData = m_font->glyphDataForCharacter(upperText[0], false, SmallCapsVariant).fontData; 752 currentFontData = m_font->glyphDataForCharacter(upperText[0], false, SmallCapsVariant).fontData;
681 ASSERT(!upperText.is8Bit()); // m_normalizedBuffer is 16 bit, theref ore upperText is 16 bit, even after we call makeUpper(). 753 ASSERT(!upperText.is8Bit()); // m_normalizedBuffer is 16 bit, theref ore upperText is 16 bit, even after we call makeUpper().
682 hb_buffer_add_utf16(harfBuzzBuffer.get(), toUint16(upperText.charact ers16()), currentRun->numCharacters(), 0, currentRun->numCharacters()); 754 hb_buffer_add_utf16(harfBuzzBuffer.get(), toUint16(upperText.charact ers16()), currentRun->numCharacters(), 0, currentRun->numCharacters());
683 } else { 755 } else {
684 hb_buffer_add_utf16(harfBuzzBuffer.get(), toUint16(m_normalizedBuffe r.get() + currentRun->startIndex()), currentRun->numCharacters(), 0, currentRun- >numCharacters()); 756 hb_buffer_add_utf16(harfBuzzBuffer.get(), toUint16(m_normalizedBuffe r.get() + currentRun->startIndex()), currentRun->numCharacters(), 0, currentRun- >numCharacters());
685 } 757 }
686 758
687 if (m_font->fontDescription().orientation() == Vertical) 759 if (m_font->fontDescription().orientation() == Vertical)
688 face->setScriptForVerticalGlyphSubstitution(harfBuzzBuffer.get()); 760 face->setScriptForVerticalGlyphSubstitution(harfBuzzBuffer.get());
689 761
690 HarfBuzzScopedPtr<hb_font_t> harfBuzzFont(face->createFont(), hb_font_de stroy); 762 HarfBuzzScopedPtr<hb_font_t> harfBuzzFont(face->createFont(m_font->types ettingFeatures()), hb_font_destroy);
691 763
692 hb_shape(harfBuzzFont.get(), harfBuzzBuffer.get(), m_features.isEmpty() ? 0 : m_features.data(), m_features.size()); 764 hb_shape(harfBuzzFont.get(), harfBuzzBuffer.get(), m_features.isEmpty() ? 0 : m_features.data(), m_features.size());
693 currentRun->applyShapeResult(harfBuzzBuffer.get()); 765 currentRun->applyShapeResult(harfBuzzBuffer.get());
694 setGlyphPositionsForHarfBuzzRun(currentRun, harfBuzzBuffer.get()); 766 setGlyphPositionsForHarfBuzzRun(currentRun, harfBuzzBuffer.get());
695 767
696 runCache.insert(key, new CachedShapingResults(harfBuzzBuffer.get(), m_fo nt, props.direction)); 768 runCache.insert(key, new CachedShapingResults(harfBuzzBuffer.get(), m_fo nt, props.direction));
697 769
698 harfBuzzBuffer.set(hb_buffer_create()); 770 harfBuzzBuffer.set(hb_buffer_create());
699 hb_buffer_set_unicode_funcs(harfBuzzBuffer.get(), hb_icu_get_unicode_fun cs()); 771 hb_buffer_set_unicode_funcs(harfBuzzBuffer.get(), hb_icu_get_unicode_fun cs());
700 } 772 }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 if (!foundToX) 946 if (!foundToX)
875 toX = m_run.rtl() ? 0 : m_totalWidth; 947 toX = m_run.rtl() ? 0 : m_totalWidth;
876 948
877 // Using floorf() and roundf() as the same as mac port. 949 // Using floorf() and roundf() as the same as mac port.
878 if (fromX < toX) 950 if (fromX < toX)
879 return FloatRect(floorf(point.x() + fromX), point.y(), roundf(toX - from X), height); 951 return FloatRect(floorf(point.x() + fromX), point.y(), roundf(toX - from X), height);
880 return FloatRect(floorf(point.x() + toX), point.y(), roundf(fromX - toX), he ight); 952 return FloatRect(floorf(point.x() + toX), point.y(), roundf(fromX - toX), he ight);
881 } 953 }
882 954
883 } // namespace WebCore 955 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698