1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/*
2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com *
4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */
7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDrawPaint.h"
98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkAnimateMaker.h"
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDrawColor.h"
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDrawShader.h"
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkMaskFilter.h"
138d4dc714da9fc598d48ad3e360870aee622094c4reed@google.com#include "SkPaintPart.h"
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPathEffect.h"
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comenum SkPaint_Functions {
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_FUNCTION(measureText)
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comenum SkPaint_Properties {
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_PROPERTY(ascent),
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_PROPERTY(descent)
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// !!! in the future, this could be compiled by build-condensed-info into an array of parameters
268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// with a lookup table to find the first parameter -- for now, it is iteratively searched through
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comconst SkFunctionParamType SkDrawPaint::fFunctionParameters[] = {
288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    (SkFunctionParamType) SkType_String,
298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    (SkFunctionParamType) 0 // terminator for parameter list (there may be multiple parameter lists)
308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#if SK_USE_CONDENSED_INFO == 0
348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comconst SkMemberInfo SkDrawPaint::fInfo[] = {
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER(antiAlias, Boolean),
378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER_PROPERTY(ascent, Float),
388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER(color, Color),
398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER_PROPERTY(descent, Float),
408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER(fakeBold, Boolean),
418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER(filterBitmap, Boolean),
428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER(linearText, Boolean),
438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER(maskFilter, MaskFilter),
448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER_FUNCTION(measureText, Float),
458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER(pathEffect, PathEffect),
468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER(shader, Shader),
478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER(strikeThru, Boolean),
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER(stroke, Boolean),
498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER(strokeCap, Cap),
508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER(strokeJoin, Join),
518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER(strokeMiter, Float),
528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER(strokeWidth, Float),
538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER(style, Style),
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER(textAlign, Align),
558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER(textScaleX, Float),
568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER(textSize, Float),
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER(textSkewX, Float),
588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER(typeface, Typeface),
598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER(underline, Boolean),
608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SK_MEMBER(xfermode, Xfermode)
618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comDEFINE_GET_MEMBER(SkDrawPaint);
668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkDrawPaint::SkDrawPaint() : antiAlias(-1), color(NULL), fakeBold(-1), filterBitmap(-1),
688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    linearText(-1), maskFilter((SkDrawMaskFilter*) -1), pathEffect((SkDrawPathEffect*) -1),
698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    shader((SkDrawShader*) -1), strikeThru(-1), stroke(-1),
7082065d667f64e232bcde2ad849756a6096fcbe6freed@google.com    strokeCap((SkPaint::Cap) -1), strokeJoin((SkPaint::Join) -1), strokeMiter(SK_ScalarNaN),
718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    strokeWidth(SK_ScalarNaN), style((SkPaint::Style) -1),
7282065d667f64e232bcde2ad849756a6096fcbe6freed@google.com    textAlign((SkPaint::Align) -1), textScaleX(SK_ScalarNaN), textSize(SK_ScalarNaN),
738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    textSkewX(SK_ScalarNaN), typeface((SkDrawTypeface*) -1),
7482065d667f64e232bcde2ad849756a6096fcbe6freed@google.com    underline(-1), xfermode((SkXfermode::Mode) -1), fOwnsColor(false), fOwnsMaskFilter(false),
758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fOwnsPathEffect(false), fOwnsShader(false), fOwnsTypeface(false) {
768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkDrawPaint::~SkDrawPaint() {
798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (fOwnsColor)
808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        delete color;
818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (fOwnsMaskFilter)
828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        delete maskFilter;
838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (fOwnsPathEffect)
848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        delete pathEffect;
858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (fOwnsShader)
868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        delete shader;
878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (fOwnsTypeface)
888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        delete typeface;
898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
91d6caf2eefd0dc05d0855bf8419bb8d4aca903f6ctomhudson@google.combool SkDrawPaint::add(SkAnimateMaker* maker, SkDisplayable* child) {
928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkASSERT(child && child->isPaintPart());
938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkPaintPart* part = (SkPaintPart*) child;
94d6caf2eefd0dc05d0855bf8419bb8d4aca903f6ctomhudson@google.com    if (part->add() && maker)
95d6caf2eefd0dc05d0855bf8419bb8d4aca903f6ctomhudson@google.com        maker->setErrorCode(SkDisplayXMLParserError::kErrorAddingToPaint);
968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    return true;
978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkDisplayable* SkDrawPaint::deepCopy(SkAnimateMaker* maker) {
1008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDrawColor* tempColor = color;
1018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    color = NULL;
1028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDrawPaint* copy = (SkDrawPaint*) INHERITED::deepCopy(maker);
1038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    color = tempColor;
1048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    tempColor = (SkDrawColor*) color->deepCopy(maker);
1058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    tempColor->setParent(copy);
1068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    tempColor->add();
1078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    copy->fOwnsColor = true;
1088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    return copy;
1098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
1108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkDrawPaint::draw(SkAnimateMaker& maker) {
1128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkPaint* paint = maker.fPaint;
1138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    setupPaint(paint);
1148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    return false;
1158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
1168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_DUMP_ENABLED
1188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDrawPaint::dump(SkAnimateMaker* maker) {
1198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    dumpBase(maker);
1208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    dumpAttrs(maker);
1218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool closedYet = false;
1228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDisplayList::fIndent +=4;
1238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //should i say if (maskFilter && ...?
1248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (maskFilter != (SkDrawMaskFilter*)-1) {
1258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkDebugf(">\n");
1268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        maskFilter->dump(maker);
1278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        closedYet = true;
1288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
1298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (pathEffect != (SkDrawPathEffect*) -1) {
1308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        if (closedYet == false) {
1318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            SkDebugf(">\n");
1328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            closedYet = true;
1338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
1348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        pathEffect->dump(maker);
1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
1368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (fOwnsTypeface) {
1378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        if (closedYet == false) {
1388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            SkDebugf(">\n");
1398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            closedYet = true;
1408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
1418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        typeface->dump(maker);
1428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
1438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDisplayList::fIndent -= 4;
1448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    dumpChildren(maker, closedYet);
1458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
1468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
14782065d667f64e232bcde2ad849756a6096fcbe6freed@google.com
14882065d667f64e232bcde2ad849756a6096fcbe6freed@google.comvoid SkDrawPaint::executeFunction(SkDisplayable* target, int index,
1498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkTDArray<SkScriptValue>& parameters, SkDisplayTypes type,
1508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkScriptValue* scriptValue) {
1518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        if (scriptValue == NULL)
1528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            return;
1538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkASSERT(target == this);
1548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    switch (index) {
1558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        case SK_FUNCTION(measureText): {
1568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            SkASSERT(parameters.count() == 1);
1578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            SkASSERT(type == SkType_Float);
1588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            SkPaint paint;
1598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            setupPaint(&paint);
1608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            scriptValue->fType = SkType_Float;
1618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            SkASSERT(parameters[0].fType == SkType_String);
16282065d667f64e232bcde2ad849756a6096fcbe6freed@google.com            scriptValue->fOperand.fScalar = paint.measureText(parameters[0].fOperand.fString->c_str(),
16382065d667f64e232bcde2ad849756a6096fcbe6freed@google.com                parameters[0].fOperand.fString->size());
16482065d667f64e232bcde2ad849756a6096fcbe6freed@google.com//          SkDebugf("measureText: %s = %g\n", parameters[0].fOperand.fString->c_str(),
1658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com//              scriptValue->fOperand.fScalar / 65536.0f);
1668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            } break;
1678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        default:
1688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            SkASSERT(0);
1698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
1708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
1718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comconst SkFunctionParamType* SkDrawPaint::getFunctionsParameters() {
1738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    return fFunctionParameters;
1748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
1758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkDrawPaint::getProperty(int index, SkScriptValue* value) const {
1778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkPaint::FontMetrics    metrics;
1788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkPaint paint;
1798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    setupPaint(&paint);
1808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    paint.getFontMetrics(&metrics);
1818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    switch (index) {
1828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        case SK_PROPERTY(ascent):
1838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            value->fOperand.fScalar = metrics.fAscent;
1848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            break;
1858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        case SK_PROPERTY(descent):
1868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            value->fOperand.fScalar = metrics.fDescent;
1878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            break;
18882065d667f64e232bcde2ad849756a6096fcbe6freed@google.com        // should consider returning fLeading as well (or roll it into ascent/descent somehow
1898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        default:
1908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            SkASSERT(0);
1918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            return false;
1928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
1938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    value->fType = SkType_Float;
1948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    return true;
1958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
1968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkDrawPaint::resolveIDs(SkAnimateMaker& maker, SkDisplayable* origDisp, SkApply* ) {
1988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkASSERT(origDisp->isPaint());
1998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDrawPaint* original = (SkDrawPaint*) origDisp;
2008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (fOwnsColor && maker.resolveID(color, original->color) == false)
2018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        return true;
2028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (fOwnsMaskFilter && maker.resolveID(maskFilter, original->maskFilter) == false)
2038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        return true;
2048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (fOwnsPathEffect && maker.resolveID(pathEffect, original->pathEffect) == false)
2058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        return true;
2068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (fOwnsShader && maker.resolveID(shader, original->shader) == false)
2078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        return true;
2088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (fOwnsTypeface && maker.resolveID(typeface, original->typeface) == false)
2098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        return true;
21082065d667f64e232bcde2ad849756a6096fcbe6freed@google.com    return false; // succeeded
2118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
2128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDrawPaint::setupPaint(SkPaint* paint) const {
2148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (antiAlias != -1)
2158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint->setAntiAlias(SkToBool(antiAlias));
2168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (color != NULL)
2178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint->setColor(color->getColor());
2188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (fakeBold != -1)
2198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint->setFakeBoldText(SkToBool(fakeBold));
2208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (filterBitmap != -1)
2214469938e92d779dff05e745559e67907bbf21e78reed@google.com        paint->setFilterLevel(filterBitmap ? SkPaint::kLow_FilterLevel : SkPaint::kNone_FilterLevel);
2228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //  stroke is legacy; style setting if present overrides stroke
2238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (stroke != -1)
2248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint->setStyle(SkToBool(stroke) ? SkPaint::kStroke_Style : SkPaint::kFill_Style);
225e80c2bc80e2939936744a9001ba2f24e6f97903dtfarina@chromium.org    if (style != -1)
2268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint->setStyle((SkPaint::Style) style);
2278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (linearText != -1)
2288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint->setLinearText(SkToBool(linearText));
2298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (maskFilter == NULL)
2308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint->setMaskFilter(NULL);
2318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    else if (maskFilter != (SkDrawMaskFilter*) -1)
23282065d667f64e232bcde2ad849756a6096fcbe6freed@google.com        SkSafeUnref(paint->setMaskFilter(maskFilter->getMaskFilter()));
2338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (pathEffect == NULL)
2348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint->setPathEffect(NULL);
2358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    else if (pathEffect != (SkDrawPathEffect*) -1)
23682065d667f64e232bcde2ad849756a6096fcbe6freed@google.com        SkSafeUnref(paint->setPathEffect(pathEffect->getPathEffect()));
2378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (shader == NULL)
2388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint->setShader(NULL);
2398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    else if (shader != (SkDrawShader*) -1)
24082065d667f64e232bcde2ad849756a6096fcbe6freed@google.com        SkSafeUnref(paint->setShader(shader->getShader()));
2418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (strikeThru != -1)
2428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint->setStrikeThruText(SkToBool(strikeThru));
243e80c2bc80e2939936744a9001ba2f24e6f97903dtfarina@chromium.org    if (strokeCap != -1)
2448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint->setStrokeCap((SkPaint::Cap) strokeCap);
245e80c2bc80e2939936744a9001ba2f24e6f97903dtfarina@chromium.org    if (strokeJoin != -1)
2468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint->setStrokeJoin((SkPaint::Join) strokeJoin);
2478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (SkScalarIsNaN(strokeMiter) == false)
2488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint->setStrokeMiter(strokeMiter);
2498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (SkScalarIsNaN(strokeWidth) == false)
2508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint->setStrokeWidth(strokeWidth);
251e80c2bc80e2939936744a9001ba2f24e6f97903dtfarina@chromium.org    if (textAlign != -1)
2528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint->setTextAlign((SkPaint::Align) textAlign);
2538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (SkScalarIsNaN(textScaleX) == false)
2548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint->setTextScaleX(textScaleX);
2558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (SkScalarIsNaN(textSize) == false)
2568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint->setTextSize(textSize);
2578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (SkScalarIsNaN(textSkewX) == false)
2588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint->setTextSkewX(textSkewX);
2598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (typeface == NULL)
2608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint->setTypeface(NULL);
2618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    else if (typeface != (SkDrawTypeface*) -1)
26282065d667f64e232bcde2ad849756a6096fcbe6freed@google.com        SkSafeUnref(paint->setTypeface(typeface->getTypeface()));
2638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (underline != -1)
2648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint->setUnderlineText(SkToBool(underline));
265e80c2bc80e2939936744a9001ba2f24e6f97903dtfarina@chromium.org    if (xfermode != -1)
2660f0cfaecf2c52e5fcb033c43df06f07a81c7b0c2reed@android.com        paint->setXfermodeMode((SkXfermode::Mode) xfermode);
2678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
268