aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar bungeman <bungeman@google.com>2016-04-13 13:50:20 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-04-13 13:50:21 -0700
commitd3b63d3244add67b1d087123f36a418f7fd7ec0f (patch)
tree3e51c8294e1aeb3ec7c1c95d0d8b490630eba4c5 /src
parentb461d3457567cf79a3efac3123c00f7afc37fecb (diff)
Respect FC_MATRIX and FC_EMBOLDEN as extra font parameters.
A font consists of a set of data and a set of parameters to that data. For example a ttc font consists of the full font data parameterized by the index. In addition to the index, FontConfig allows specifying a matrix and embolden flag. In the future there may also be additional parameters of this sort, for example which color palette to use. This does not provide a way to serialize these parameters. Adding this here provides a nice place to experiment with doing so. GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1890533002 Review URL: https://codereview.chromium.org/1890533002
Diffstat (limited to 'src')
-rw-r--r--src/ports/SkFontMgr_fontconfig.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp
index 393265c542..b672f43177 100644
--- a/src/ports/SkFontMgr_fontconfig.cpp
+++ b/src/ports/SkFontMgr_fontconfig.cpp
@@ -125,6 +125,14 @@ typedef SkAutoFc<FcLangSet, FcLangSetCreate, FcLangSetDestroy> SkAutoFcLangSet;
typedef SkAutoFc<FcObjectSet, FcObjectSetCreate, FcObjectSetDestroy> SkAutoFcObjectSet;
typedef SkAutoFc<FcPattern, FcPatternCreate, FcPatternDestroy> SkAutoFcPattern;
+static bool get_bool(FcPattern* pattern, const char object[], bool missing = false) {
+ FcBool value;
+ if (FcPatternGetBool(pattern, object, 0, &value) != FcResultMatch) {
+ return missing;
+ }
+ return value;
+}
+
static int get_int(FcPattern* pattern, const char object[], int missing) {
int value;
if (FcPatternGetInteger(pattern, object, 0, &value) != FcResultMatch) {
@@ -141,6 +149,14 @@ static const char* get_string(FcPattern* pattern, const char object[], const cha
return (const char*)value;
}
+static const FcMatrix* get_matrix(FcPattern* pattern, const char object[]) {
+ FcMatrix* matrix;
+ if (FcPatternGetMatrix(pattern, object, 0, &matrix) != FcResultMatch) {
+ return nullptr;
+ }
+ return matrix;
+}
+
enum SkWeakReturn {
kIsWeak_WeakReturn,
kIsStrong_WeakReturn,
@@ -430,6 +446,31 @@ public:
return SkStream::NewFromFile(get_string(fPattern, FC_FILE));
}
+ void onFilterRec(SkScalerContextRec* rec) const override {
+ const FcMatrix* fcMatrix = get_matrix(fPattern, FC_MATRIX);
+ if (fcMatrix) {
+ // fPost2x2 is column-major, left handed (y down).
+ // FcMatrix is column-major, right handed (y up).
+ SkMatrix fm;
+ fm.setAll(fcMatrix->xx,-fcMatrix->xy, 0,
+ -fcMatrix->yx, fcMatrix->yy, 0,
+ 0 , 0 , 1);
+
+ SkMatrix sm;
+ rec->getMatrixFrom2x2(&sm);
+
+ sm.preConcat(fm);
+ rec->fPost2x2[0][0] = sm.getScaleX();
+ rec->fPost2x2[0][1] = sm.getSkewX();
+ rec->fPost2x2[1][0] = sm.getSkewY();
+ rec->fPost2x2[1][1] = sm.getScaleY();
+ }
+ if (get_bool(fPattern, FC_EMBOLDEN)) {
+ rec->fFlags |= SkScalerContext::kEmbolden_Flag;
+ }
+ this->INHERITED::onFilterRec(rec);
+ }
+
virtual ~SkTypeface_fontconfig() {
// Hold the lock while unrefing the pattern.
FCLocker lock;