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