aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/text/GrTextUtils.cpp
blob: ec5389c4647bcbfde7fecd019878e1de57c45638 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "GrTextUtils.h"
#include "GrContext.h"
#include "SkGlyphCache.h"
#include "SkGr.h"
#include "SkPaint.h"
#include "SkTextBlobRunIterator.h"

void GrTextUtils::Paint::initFilteredColor() {
    GrColor4f filteredColor = SkColorToUnpremulGrColor4f(fPaint->getColor(), *fDstColorSpaceInfo);
    if (fPaint->getColorFilter()) {
        filteredColor = GrColor4f::FromSkColor4f(
            fPaint->getColorFilter()->filterColor4f(filteredColor.toSkColor4f()));
    }
    fFilteredPremulColor = filteredColor.premul().toGrColor();
}


bool GrTextUtils::RunPaint::modifyForRun(std::function<void(SkPaint*)> paintModFunc) {
    if (!fModifiedPaint.isValid()) {
        fModifiedPaint.init(fOriginalPaint->skPaint());
        fPaint = fModifiedPaint.get();
    }
    paintModFunc(fModifiedPaint.get());
    return true;
}

bool GrTextUtils::PathTextIter::next(const SkGlyph** skGlyph, const SkPath** path, SkScalar* xpos) {
    SkASSERT(skGlyph);
    SkASSERT(path);
    SkASSERT(xpos);
    if (fText < fStop) {
        const SkGlyph& glyph = fGlyphCacheProc(fCache.get(), &fText, fStop);

        fXPos += fPrevAdvance * fScale;
        SkASSERT(0 == fXYIndex || 1 == fXYIndex);
        fPrevAdvance = SkFloatToScalar((&glyph.fAdvanceX)[fXYIndex]);

        if (glyph.fWidth) {
            if (SkMask::kARGB32_Format == glyph.fMaskFormat) {
                *skGlyph = &glyph;
                *path = nullptr;
            } else {
                *skGlyph = nullptr;
                *path = fCache->findPath(glyph);
            }
        } else {
            *skGlyph = nullptr;
            *path = nullptr;
        }
        *xpos = fXPos;
        return true;
    }
    return false;
}