other-licenses/skia-npapi/ANPPaint.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/other-licenses/skia-npapi/ANPPaint.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,209 @@
     1.4 +/*
     1.5 + * Copyright 2008, The Android Open Source Project
     1.6 + *
     1.7 + * Redistribution and use in source and binary forms, with or without
     1.8 + * modification, are permitted provided that the following conditions
     1.9 + * are met:
    1.10 + *  * Redistributions of source code must retain the above copyright
    1.11 + *    notice, this list of conditions and the following disclaimer.
    1.12 + *  * Redistributions in binary form must reproduce the above copyright
    1.13 + *    notice, this list of conditions and the following disclaimer in the
    1.14 + *    documentation and/or other materials provided with the distribution.
    1.15 + *
    1.16 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
    1.17 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.18 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    1.19 + * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    1.20 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    1.21 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    1.22 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    1.23 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
    1.24 + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.25 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.26 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.27 + */
    1.28 +
    1.29 +// must include config.h first for webkit to fiddle with new/delete
    1.30 +#include "SkANP.h"
    1.31 +#include "SkTypeface.h"
    1.32 +
    1.33 +static ANPPaint* anp_newPaint() {
    1.34 +    return new ANPPaint;
    1.35 +}
    1.36 +
    1.37 +static void anp_deletePaint(ANPPaint* paint) {
    1.38 +    delete paint;
    1.39 +}
    1.40 +
    1.41 +static ANPPaintFlags anp_getFlags(const ANPPaint* paint) {
    1.42 +    return paint->getFlags();
    1.43 +}
    1.44 +
    1.45 +static void anp_setFlags(ANPPaint* paint, ANPPaintFlags flags) {
    1.46 +    paint->setFlags(flags);
    1.47 +}
    1.48 +
    1.49 +static ANPColor anp_getColor(const ANPPaint* paint) {
    1.50 +    return paint->getColor();
    1.51 +}
    1.52 +
    1.53 +static void anp_setColor(ANPPaint* paint, ANPColor color) {
    1.54 +    paint->setColor(color);
    1.55 +}
    1.56 +
    1.57 +static ANPPaintStyle anp_getStyle(const ANPPaint* paint) {
    1.58 +    return paint->getStyle();
    1.59 +}
    1.60 +
    1.61 +static void anp_setStyle(ANPPaint* paint, ANPPaintStyle style) {
    1.62 +    paint->setStyle(static_cast<SkPaint::Style>(style));
    1.63 +}
    1.64 +
    1.65 +static float anp_getStrokeWidth(const ANPPaint* paint) {
    1.66 +    return SkScalarToFloat(paint->getStrokeWidth());
    1.67 +}
    1.68 +
    1.69 +static float anp_getStrokeMiter(const ANPPaint* paint) {
    1.70 +    return SkScalarToFloat(paint->getStrokeMiter());
    1.71 +}
    1.72 +
    1.73 +static ANPPaintCap anp_getStrokeCap(const ANPPaint* paint) {
    1.74 +    return paint->getStrokeCap();
    1.75 +}
    1.76 +
    1.77 +static ANPPaintJoin anp_getStrokeJoin(const ANPPaint* paint) {
    1.78 +    return paint->getStrokeJoin();
    1.79 +}
    1.80 +
    1.81 +static void anp_setStrokeWidth(ANPPaint* paint, float width) {
    1.82 +    paint->setStrokeWidth(SkFloatToScalar(width));
    1.83 +}
    1.84 +
    1.85 +static void anp_setStrokeMiter(ANPPaint* paint, float miter) {
    1.86 +    paint->setStrokeMiter(SkFloatToScalar(miter));
    1.87 +}
    1.88 +
    1.89 +static void anp_setStrokeCap(ANPPaint* paint, ANPPaintCap cap) {
    1.90 +    paint->setStrokeCap(static_cast<SkPaint::Cap>(cap));
    1.91 +}
    1.92 +
    1.93 +static void anp_setStrokeJoin(ANPPaint* paint, ANPPaintJoin join) {
    1.94 +    paint->setStrokeJoin(static_cast<SkPaint::Join>(join));
    1.95 +}
    1.96 +
    1.97 +static ANPTextEncoding anp_getTextEncoding(const ANPPaint* paint) {
    1.98 +    return paint->getTextEncoding();
    1.99 +}
   1.100 +
   1.101 +static ANPPaintAlign anp_getTextAlign(const ANPPaint* paint) {
   1.102 +    return paint->getTextAlign();
   1.103 +}
   1.104 +
   1.105 +static float anp_getTextSize(const ANPPaint* paint) {
   1.106 +    return SkScalarToFloat(paint->getTextSize());
   1.107 +}
   1.108 +
   1.109 +static float anp_getTextScaleX(const ANPPaint* paint) {
   1.110 +    return SkScalarToFloat(paint->getTextScaleX());
   1.111 +}
   1.112 +
   1.113 +static float anp_getTextSkewX(const ANPPaint* paint) {
   1.114 +    return SkScalarToFloat(paint->getTextSkewX());
   1.115 +}
   1.116 +
   1.117 +static ANPTypeface* anp_getTypeface(const ANPPaint* paint) {
   1.118 +    return reinterpret_cast<ANPTypeface*>(paint->getTypeface());
   1.119 +}
   1.120 +
   1.121 +static void anp_setTextEncoding(ANPPaint* paint, ANPTextEncoding encoding) {
   1.122 +    paint->setTextEncoding(static_cast<SkPaint::TextEncoding>(encoding));
   1.123 +}
   1.124 +
   1.125 +static void anp_setTextAlign(ANPPaint* paint, ANPPaintAlign align) {
   1.126 +    paint->setTextAlign(static_cast<SkPaint::Align>(align));
   1.127 +}
   1.128 +
   1.129 +static void anp_setTextSize(ANPPaint* paint, float textSize) {
   1.130 +    paint->setTextSize(SkFloatToScalar(textSize));
   1.131 +}
   1.132 +
   1.133 +static void anp_setTextScaleX(ANPPaint* paint, float scaleX) {
   1.134 +    paint->setTextScaleX(SkFloatToScalar(scaleX));
   1.135 +}
   1.136 +
   1.137 +static void anp_setTextSkewX(ANPPaint* paint, float skewX) {
   1.138 +    paint->setTextSkewX(SkFloatToScalar(skewX));
   1.139 +}
   1.140 +
   1.141 +static void anp_setTypeface(ANPPaint* paint, ANPTypeface* tf) {
   1.142 +    paint->setTypeface(tf);
   1.143 +}
   1.144 +
   1.145 +static float anp_measureText(ANPPaint* paint, const void* text,
   1.146 +                             uint32_t byteLength, ANPRectF* bounds) {
   1.147 +    SkScalar w = paint->measureText(text, byteLength,
   1.148 +                                    reinterpret_cast<SkRect*>(bounds));
   1.149 +    return SkScalarToFloat(w);
   1.150 +}
   1.151 +
   1.152 +/** Return the number of unichars specifed by the text.
   1.153 + If widths is not null, returns the array of advance widths for each
   1.154 + unichar.
   1.155 + If bounds is not null, returns the array of bounds for each unichar.
   1.156 + */
   1.157 +static int anp_getTextWidths(ANPPaint* paint, const void* text,
   1.158 +                       uint32_t byteLength, float widths[], ANPRectF bounds[]) {
   1.159 +    return paint->getTextWidths(text, byteLength, widths,
   1.160 +                                reinterpret_cast<SkRect*>(bounds));
   1.161 +}
   1.162 +
   1.163 +static float anp_getFontMetrics(ANPPaint* paint, ANPFontMetrics* metrics) {
   1.164 +    SkPaint::FontMetrics fm;
   1.165 +    SkScalar spacing = paint->getFontMetrics(&fm);
   1.166 +    if (metrics) {
   1.167 +        metrics->fTop = SkScalarToFloat(fm.fTop);
   1.168 +        metrics->fAscent = SkScalarToFloat(fm.fAscent);
   1.169 +        metrics->fDescent = SkScalarToFloat(fm.fDescent);
   1.170 +        metrics->fBottom = SkScalarToFloat(fm.fBottom);
   1.171 +        metrics->fLeading = SkScalarToFloat(fm.fLeading);
   1.172 +    }
   1.173 +    return SkScalarToFloat(spacing);
   1.174 +}
   1.175 +
   1.176 +///////////////////////////////////////////////////////////////////////////////
   1.177 +
   1.178 +#define ASSIGN(obj, name)   (obj)->name = anp_##name
   1.179 +
   1.180 +void InitPaintInterface(ANPPaintInterfaceV0* i) {
   1.181 +    ASSIGN(i, newPaint);
   1.182 +    ASSIGN(i, deletePaint);
   1.183 +    ASSIGN(i, getFlags);
   1.184 +    ASSIGN(i, setFlags);
   1.185 +    ASSIGN(i, getColor);
   1.186 +    ASSIGN(i, setColor);
   1.187 +    ASSIGN(i, getStyle);
   1.188 +    ASSIGN(i, setStyle);
   1.189 +    ASSIGN(i, getStrokeWidth);
   1.190 +    ASSIGN(i, getStrokeMiter);
   1.191 +    ASSIGN(i, getStrokeCap);
   1.192 +    ASSIGN(i, getStrokeJoin);
   1.193 +    ASSIGN(i, setStrokeWidth);
   1.194 +    ASSIGN(i, setStrokeMiter);
   1.195 +    ASSIGN(i, setStrokeCap);
   1.196 +    ASSIGN(i, setStrokeJoin);
   1.197 +    ASSIGN(i, getTextEncoding);
   1.198 +    ASSIGN(i, getTextAlign);
   1.199 +    ASSIGN(i, getTextSize);
   1.200 +    ASSIGN(i, getTextScaleX);
   1.201 +    ASSIGN(i, getTextSkewX);
   1.202 +    ASSIGN(i, getTypeface);
   1.203 +    ASSIGN(i, setTextEncoding);
   1.204 +    ASSIGN(i, setTextAlign);
   1.205 +    ASSIGN(i, setTextSize);
   1.206 +    ASSIGN(i, setTextScaleX);
   1.207 +    ASSIGN(i, setTextSkewX);
   1.208 +    ASSIGN(i, setTypeface);
   1.209 +    ASSIGN(i, measureText);
   1.210 +    ASSIGN(i, getTextWidths);
   1.211 +    ASSIGN(i, getFontMetrics);
   1.212 +}

mercurial