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

Side by Side Diff: src/ports/SkFontMgr_fontconfig.cpp

Issue 1890533002: Respect FC_MATRIX and FC_EMBOLDEN as extra font parameters. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix handedness. Created 4 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkDataTable.h" 8 #include "SkDataTable.h"
9 #include "SkFixed.h" 9 #include "SkFixed.h"
10 #include "SkFontDescriptor.h" 10 #include "SkFontDescriptor.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 explicit SkAutoFc(T* obj) : SkAutoTCallVProc<T, FcTDestroy<T, D> >(obj) {} 118 explicit SkAutoFc(T* obj) : SkAutoTCallVProc<T, FcTDestroy<T, D> >(obj) {}
119 }; 119 };
120 120
121 typedef SkAutoFc<FcCharSet, FcCharSetCreate, FcCharSetDestroy> SkAutoFcCharSet; 121 typedef SkAutoFc<FcCharSet, FcCharSetCreate, FcCharSetDestroy> SkAutoFcCharSet;
122 typedef SkAutoFc<FcConfig, FcConfigCreate, FcConfigDestroy> SkAutoFcConfig; 122 typedef SkAutoFc<FcConfig, FcConfigCreate, FcConfigDestroy> SkAutoFcConfig;
123 typedef SkAutoFc<FcFontSet, FcFontSetCreate, FcFontSetDestroy> SkAutoFcFontSet; 123 typedef SkAutoFc<FcFontSet, FcFontSetCreate, FcFontSetDestroy> SkAutoFcFontSet;
124 typedef SkAutoFc<FcLangSet, FcLangSetCreate, FcLangSetDestroy> SkAutoFcLangSet; 124 typedef SkAutoFc<FcLangSet, FcLangSetCreate, FcLangSetDestroy> SkAutoFcLangSet;
125 typedef SkAutoFc<FcObjectSet, FcObjectSetCreate, FcObjectSetDestroy> SkAutoFcObj ectSet; 125 typedef SkAutoFc<FcObjectSet, FcObjectSetCreate, FcObjectSetDestroy> SkAutoFcObj ectSet;
126 typedef SkAutoFc<FcPattern, FcPatternCreate, FcPatternDestroy> SkAutoFcPattern; 126 typedef SkAutoFc<FcPattern, FcPatternCreate, FcPatternDestroy> SkAutoFcPattern;
127 127
128 static bool get_bool(FcPattern* pattern, const char object[], bool missing = fal se) {
129 FcBool value;
130 if (FcPatternGetBool(pattern, object, 0, &value) != FcResultMatch) {
131 return missing;
132 }
133 return value;
134 }
135
128 static int get_int(FcPattern* pattern, const char object[], int missing) { 136 static int get_int(FcPattern* pattern, const char object[], int missing) {
129 int value; 137 int value;
130 if (FcPatternGetInteger(pattern, object, 0, &value) != FcResultMatch) { 138 if (FcPatternGetInteger(pattern, object, 0, &value) != FcResultMatch) {
131 return missing; 139 return missing;
132 } 140 }
133 return value; 141 return value;
134 } 142 }
135 143
136 static const char* get_string(FcPattern* pattern, const char object[], const cha r* missing = "") { 144 static const char* get_string(FcPattern* pattern, const char object[], const cha r* missing = "") {
137 FcChar8* value; 145 FcChar8* value;
138 if (FcPatternGetString(pattern, object, 0, &value) != FcResultMatch) { 146 if (FcPatternGetString(pattern, object, 0, &value) != FcResultMatch) {
139 return missing; 147 return missing;
140 } 148 }
141 return (const char*)value; 149 return (const char*)value;
142 } 150 }
143 151
152 static const FcMatrix* get_matrix(FcPattern* pattern, const char object[]) {
153 FcMatrix* matrix;
154 if (FcPatternGetMatrix(pattern, object, 0, &matrix) != FcResultMatch) {
155 return nullptr;
156 }
157 return matrix;
158 }
159
144 enum SkWeakReturn { 160 enum SkWeakReturn {
145 kIsWeak_WeakReturn, 161 kIsWeak_WeakReturn,
146 kIsStrong_WeakReturn, 162 kIsStrong_WeakReturn,
147 kNoId_WeakReturn 163 kNoId_WeakReturn
148 }; 164 };
149 /** Ideally there would exist a call like 165 /** Ideally there would exist a call like
150 * FcResult FcPatternIsWeak(pattern, object, id, FcBool* isWeak); 166 * FcResult FcPatternIsWeak(pattern, object, id, FcBool* isWeak);
151 * 167 *
152 * However, there is no such call and as of Fc 2.11.0 even FcPatternEquals igno res the weak bit. 168 * However, there is no such call and as of Fc 2.11.0 even FcPatternEquals igno res the weak bit.
153 * Currently, the only reliable way of finding the weak bit is by its effect on matching. 169 * Currently, the only reliable way of finding the weak bit is by its effect on matching.
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 desc->setPostscriptName(get_string(fPattern, FC_POSTSCRIPT_NAME)); 439 desc->setPostscriptName(get_string(fPattern, FC_POSTSCRIPT_NAME));
424 *serialize = false; 440 *serialize = false;
425 } 441 }
426 442
427 SkStreamAsset* onOpenStream(int* ttcIndex) const override { 443 SkStreamAsset* onOpenStream(int* ttcIndex) const override {
428 FCLocker lock; 444 FCLocker lock;
429 *ttcIndex = get_int(fPattern, FC_INDEX, 0); 445 *ttcIndex = get_int(fPattern, FC_INDEX, 0);
430 return SkStream::NewFromFile(get_string(fPattern, FC_FILE)); 446 return SkStream::NewFromFile(get_string(fPattern, FC_FILE));
431 } 447 }
432 448
449 void onFilterRec(SkScalerContextRec* rec) const override {
450 const FcMatrix* fcMatrix = get_matrix(fPattern, FC_MATRIX);
451 if (fcMatrix) {
452 // fPost2x2 is column-major, left handed (y down).
453 // FcMatrix is column-major, right handed (y up).
454 SkMatrix fm;
455 fm.setAll(fcMatrix->xx,-fcMatrix->xy, 0,
456 -fcMatrix->yx, fcMatrix->yy, 0,
457 0 , 0 , 1);
458
459 SkMatrix sm;
460 rec->getMatrixFrom2x2(&sm);
461
462 sm.preConcat(fm);
463 rec->fPost2x2[0][0] = sm.getScaleX();
464 rec->fPost2x2[0][1] = sm.getSkewX();
465 rec->fPost2x2[1][0] = sm.getSkewY();
466 rec->fPost2x2[1][1] = sm.getScaleY();
467 }
468 if (get_bool(fPattern, FC_EMBOLDEN)) {
469 rec->fFlags |= SkScalerContext::kEmbolden_Flag;
470 }
471 this->INHERITED::onFilterRec(rec);
472 }
473
433 virtual ~SkTypeface_fontconfig() { 474 virtual ~SkTypeface_fontconfig() {
434 // Hold the lock while unrefing the pattern. 475 // Hold the lock while unrefing the pattern.
435 FCLocker lock; 476 FCLocker lock;
436 fPattern.reset(); 477 fPattern.reset();
437 } 478 }
438 479
439 private: 480 private:
440 /** @param pattern takes ownership of the reference. */ 481 /** @param pattern takes ownership of the reference. */
441 SkTypeface_fontconfig(FcPattern* pattern) 482 SkTypeface_fontconfig(FcPattern* pattern)
442 : INHERITED(skfontstyle_from_fcpattern(pattern), 483 : INHERITED(skfontstyle_from_fcpattern(pattern),
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 return typeface.release(); 921 return typeface.release();
881 } 922 }
882 923
883 return this->matchFamilyStyle(nullptr, style); 924 return this->matchFamilyStyle(nullptr, style);
884 } 925 }
885 }; 926 };
886 927
887 SK_API SkFontMgr* SkFontMgr_New_FontConfig(FcConfig* fc) { 928 SK_API SkFontMgr* SkFontMgr_New_FontConfig(FcConfig* fc) {
888 return new SkFontMgr_fontconfig(fc); 929 return new SkFontMgr_fontconfig(fc);
889 } 930 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698