other-licenses/skia-npapi/ANPPaint.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Copyright 2008, The Android Open Source Project
michael@0 3 *
michael@0 4 * Redistribution and use in source and binary forms, with or without
michael@0 5 * modification, are permitted provided that the following conditions
michael@0 6 * are met:
michael@0 7 * * Redistributions of source code must retain the above copyright
michael@0 8 * notice, this list of conditions and the following disclaimer.
michael@0 9 * * Redistributions in binary form must reproduce the above copyright
michael@0 10 * notice, this list of conditions and the following disclaimer in the
michael@0 11 * documentation and/or other materials provided with the distribution.
michael@0 12 *
michael@0 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
michael@0 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
michael@0 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
michael@0 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
michael@0 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
michael@0 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
michael@0 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
michael@0 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
michael@0 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
michael@0 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
michael@0 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 24 */
michael@0 25
michael@0 26 // must include config.h first for webkit to fiddle with new/delete
michael@0 27 #include "SkANP.h"
michael@0 28 #include "SkTypeface.h"
michael@0 29
michael@0 30 static ANPPaint* anp_newPaint() {
michael@0 31 return new ANPPaint;
michael@0 32 }
michael@0 33
michael@0 34 static void anp_deletePaint(ANPPaint* paint) {
michael@0 35 delete paint;
michael@0 36 }
michael@0 37
michael@0 38 static ANPPaintFlags anp_getFlags(const ANPPaint* paint) {
michael@0 39 return paint->getFlags();
michael@0 40 }
michael@0 41
michael@0 42 static void anp_setFlags(ANPPaint* paint, ANPPaintFlags flags) {
michael@0 43 paint->setFlags(flags);
michael@0 44 }
michael@0 45
michael@0 46 static ANPColor anp_getColor(const ANPPaint* paint) {
michael@0 47 return paint->getColor();
michael@0 48 }
michael@0 49
michael@0 50 static void anp_setColor(ANPPaint* paint, ANPColor color) {
michael@0 51 paint->setColor(color);
michael@0 52 }
michael@0 53
michael@0 54 static ANPPaintStyle anp_getStyle(const ANPPaint* paint) {
michael@0 55 return paint->getStyle();
michael@0 56 }
michael@0 57
michael@0 58 static void anp_setStyle(ANPPaint* paint, ANPPaintStyle style) {
michael@0 59 paint->setStyle(static_cast<SkPaint::Style>(style));
michael@0 60 }
michael@0 61
michael@0 62 static float anp_getStrokeWidth(const ANPPaint* paint) {
michael@0 63 return SkScalarToFloat(paint->getStrokeWidth());
michael@0 64 }
michael@0 65
michael@0 66 static float anp_getStrokeMiter(const ANPPaint* paint) {
michael@0 67 return SkScalarToFloat(paint->getStrokeMiter());
michael@0 68 }
michael@0 69
michael@0 70 static ANPPaintCap anp_getStrokeCap(const ANPPaint* paint) {
michael@0 71 return paint->getStrokeCap();
michael@0 72 }
michael@0 73
michael@0 74 static ANPPaintJoin anp_getStrokeJoin(const ANPPaint* paint) {
michael@0 75 return paint->getStrokeJoin();
michael@0 76 }
michael@0 77
michael@0 78 static void anp_setStrokeWidth(ANPPaint* paint, float width) {
michael@0 79 paint->setStrokeWidth(SkFloatToScalar(width));
michael@0 80 }
michael@0 81
michael@0 82 static void anp_setStrokeMiter(ANPPaint* paint, float miter) {
michael@0 83 paint->setStrokeMiter(SkFloatToScalar(miter));
michael@0 84 }
michael@0 85
michael@0 86 static void anp_setStrokeCap(ANPPaint* paint, ANPPaintCap cap) {
michael@0 87 paint->setStrokeCap(static_cast<SkPaint::Cap>(cap));
michael@0 88 }
michael@0 89
michael@0 90 static void anp_setStrokeJoin(ANPPaint* paint, ANPPaintJoin join) {
michael@0 91 paint->setStrokeJoin(static_cast<SkPaint::Join>(join));
michael@0 92 }
michael@0 93
michael@0 94 static ANPTextEncoding anp_getTextEncoding(const ANPPaint* paint) {
michael@0 95 return paint->getTextEncoding();
michael@0 96 }
michael@0 97
michael@0 98 static ANPPaintAlign anp_getTextAlign(const ANPPaint* paint) {
michael@0 99 return paint->getTextAlign();
michael@0 100 }
michael@0 101
michael@0 102 static float anp_getTextSize(const ANPPaint* paint) {
michael@0 103 return SkScalarToFloat(paint->getTextSize());
michael@0 104 }
michael@0 105
michael@0 106 static float anp_getTextScaleX(const ANPPaint* paint) {
michael@0 107 return SkScalarToFloat(paint->getTextScaleX());
michael@0 108 }
michael@0 109
michael@0 110 static float anp_getTextSkewX(const ANPPaint* paint) {
michael@0 111 return SkScalarToFloat(paint->getTextSkewX());
michael@0 112 }
michael@0 113
michael@0 114 static ANPTypeface* anp_getTypeface(const ANPPaint* paint) {
michael@0 115 return reinterpret_cast<ANPTypeface*>(paint->getTypeface());
michael@0 116 }
michael@0 117
michael@0 118 static void anp_setTextEncoding(ANPPaint* paint, ANPTextEncoding encoding) {
michael@0 119 paint->setTextEncoding(static_cast<SkPaint::TextEncoding>(encoding));
michael@0 120 }
michael@0 121
michael@0 122 static void anp_setTextAlign(ANPPaint* paint, ANPPaintAlign align) {
michael@0 123 paint->setTextAlign(static_cast<SkPaint::Align>(align));
michael@0 124 }
michael@0 125
michael@0 126 static void anp_setTextSize(ANPPaint* paint, float textSize) {
michael@0 127 paint->setTextSize(SkFloatToScalar(textSize));
michael@0 128 }
michael@0 129
michael@0 130 static void anp_setTextScaleX(ANPPaint* paint, float scaleX) {
michael@0 131 paint->setTextScaleX(SkFloatToScalar(scaleX));
michael@0 132 }
michael@0 133
michael@0 134 static void anp_setTextSkewX(ANPPaint* paint, float skewX) {
michael@0 135 paint->setTextSkewX(SkFloatToScalar(skewX));
michael@0 136 }
michael@0 137
michael@0 138 static void anp_setTypeface(ANPPaint* paint, ANPTypeface* tf) {
michael@0 139 paint->setTypeface(tf);
michael@0 140 }
michael@0 141
michael@0 142 static float anp_measureText(ANPPaint* paint, const void* text,
michael@0 143 uint32_t byteLength, ANPRectF* bounds) {
michael@0 144 SkScalar w = paint->measureText(text, byteLength,
michael@0 145 reinterpret_cast<SkRect*>(bounds));
michael@0 146 return SkScalarToFloat(w);
michael@0 147 }
michael@0 148
michael@0 149 /** Return the number of unichars specifed by the text.
michael@0 150 If widths is not null, returns the array of advance widths for each
michael@0 151 unichar.
michael@0 152 If bounds is not null, returns the array of bounds for each unichar.
michael@0 153 */
michael@0 154 static int anp_getTextWidths(ANPPaint* paint, const void* text,
michael@0 155 uint32_t byteLength, float widths[], ANPRectF bounds[]) {
michael@0 156 return paint->getTextWidths(text, byteLength, widths,
michael@0 157 reinterpret_cast<SkRect*>(bounds));
michael@0 158 }
michael@0 159
michael@0 160 static float anp_getFontMetrics(ANPPaint* paint, ANPFontMetrics* metrics) {
michael@0 161 SkPaint::FontMetrics fm;
michael@0 162 SkScalar spacing = paint->getFontMetrics(&fm);
michael@0 163 if (metrics) {
michael@0 164 metrics->fTop = SkScalarToFloat(fm.fTop);
michael@0 165 metrics->fAscent = SkScalarToFloat(fm.fAscent);
michael@0 166 metrics->fDescent = SkScalarToFloat(fm.fDescent);
michael@0 167 metrics->fBottom = SkScalarToFloat(fm.fBottom);
michael@0 168 metrics->fLeading = SkScalarToFloat(fm.fLeading);
michael@0 169 }
michael@0 170 return SkScalarToFloat(spacing);
michael@0 171 }
michael@0 172
michael@0 173 ///////////////////////////////////////////////////////////////////////////////
michael@0 174
michael@0 175 #define ASSIGN(obj, name) (obj)->name = anp_##name
michael@0 176
michael@0 177 void InitPaintInterface(ANPPaintInterfaceV0* i) {
michael@0 178 ASSIGN(i, newPaint);
michael@0 179 ASSIGN(i, deletePaint);
michael@0 180 ASSIGN(i, getFlags);
michael@0 181 ASSIGN(i, setFlags);
michael@0 182 ASSIGN(i, getColor);
michael@0 183 ASSIGN(i, setColor);
michael@0 184 ASSIGN(i, getStyle);
michael@0 185 ASSIGN(i, setStyle);
michael@0 186 ASSIGN(i, getStrokeWidth);
michael@0 187 ASSIGN(i, getStrokeMiter);
michael@0 188 ASSIGN(i, getStrokeCap);
michael@0 189 ASSIGN(i, getStrokeJoin);
michael@0 190 ASSIGN(i, setStrokeWidth);
michael@0 191 ASSIGN(i, setStrokeMiter);
michael@0 192 ASSIGN(i, setStrokeCap);
michael@0 193 ASSIGN(i, setStrokeJoin);
michael@0 194 ASSIGN(i, getTextEncoding);
michael@0 195 ASSIGN(i, getTextAlign);
michael@0 196 ASSIGN(i, getTextSize);
michael@0 197 ASSIGN(i, getTextScaleX);
michael@0 198 ASSIGN(i, getTextSkewX);
michael@0 199 ASSIGN(i, getTypeface);
michael@0 200 ASSIGN(i, setTextEncoding);
michael@0 201 ASSIGN(i, setTextAlign);
michael@0 202 ASSIGN(i, setTextSize);
michael@0 203 ASSIGN(i, setTextScaleX);
michael@0 204 ASSIGN(i, setTextSkewX);
michael@0 205 ASSIGN(i, setTypeface);
michael@0 206 ASSIGN(i, measureText);
michael@0 207 ASSIGN(i, getTextWidths);
michael@0 208 ASSIGN(i, getFontMetrics);
michael@0 209 }

mercurial