michael@0: /* michael@0: * Copyright 2008, The Android Open Source Project michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions michael@0: * are met: michael@0: * * Redistributions of source code must retain the above copyright michael@0: * notice, this list of conditions and the following disclaimer. michael@0: * * Redistributions in binary form must reproduce the above copyright michael@0: * notice, this list of conditions and the following disclaimer in the michael@0: * documentation and/or other materials provided with the distribution. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY michael@0: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE michael@0: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR michael@0: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR michael@0: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, michael@0: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, michael@0: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR michael@0: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY michael@0: * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT michael@0: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE michael@0: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: */ michael@0: michael@0: // must include config.h first for webkit to fiddle with new/delete michael@0: #include "SkANP.h" michael@0: #include "SkTypeface.h" michael@0: michael@0: static ANPPaint* anp_newPaint() { michael@0: return new ANPPaint; michael@0: } michael@0: michael@0: static void anp_deletePaint(ANPPaint* paint) { michael@0: delete paint; michael@0: } michael@0: michael@0: static ANPPaintFlags anp_getFlags(const ANPPaint* paint) { michael@0: return paint->getFlags(); michael@0: } michael@0: michael@0: static void anp_setFlags(ANPPaint* paint, ANPPaintFlags flags) { michael@0: paint->setFlags(flags); michael@0: } michael@0: michael@0: static ANPColor anp_getColor(const ANPPaint* paint) { michael@0: return paint->getColor(); michael@0: } michael@0: michael@0: static void anp_setColor(ANPPaint* paint, ANPColor color) { michael@0: paint->setColor(color); michael@0: } michael@0: michael@0: static ANPPaintStyle anp_getStyle(const ANPPaint* paint) { michael@0: return paint->getStyle(); michael@0: } michael@0: michael@0: static void anp_setStyle(ANPPaint* paint, ANPPaintStyle style) { michael@0: paint->setStyle(static_cast(style)); michael@0: } michael@0: michael@0: static float anp_getStrokeWidth(const ANPPaint* paint) { michael@0: return SkScalarToFloat(paint->getStrokeWidth()); michael@0: } michael@0: michael@0: static float anp_getStrokeMiter(const ANPPaint* paint) { michael@0: return SkScalarToFloat(paint->getStrokeMiter()); michael@0: } michael@0: michael@0: static ANPPaintCap anp_getStrokeCap(const ANPPaint* paint) { michael@0: return paint->getStrokeCap(); michael@0: } michael@0: michael@0: static ANPPaintJoin anp_getStrokeJoin(const ANPPaint* paint) { michael@0: return paint->getStrokeJoin(); michael@0: } michael@0: michael@0: static void anp_setStrokeWidth(ANPPaint* paint, float width) { michael@0: paint->setStrokeWidth(SkFloatToScalar(width)); michael@0: } michael@0: michael@0: static void anp_setStrokeMiter(ANPPaint* paint, float miter) { michael@0: paint->setStrokeMiter(SkFloatToScalar(miter)); michael@0: } michael@0: michael@0: static void anp_setStrokeCap(ANPPaint* paint, ANPPaintCap cap) { michael@0: paint->setStrokeCap(static_cast(cap)); michael@0: } michael@0: michael@0: static void anp_setStrokeJoin(ANPPaint* paint, ANPPaintJoin join) { michael@0: paint->setStrokeJoin(static_cast(join)); michael@0: } michael@0: michael@0: static ANPTextEncoding anp_getTextEncoding(const ANPPaint* paint) { michael@0: return paint->getTextEncoding(); michael@0: } michael@0: michael@0: static ANPPaintAlign anp_getTextAlign(const ANPPaint* paint) { michael@0: return paint->getTextAlign(); michael@0: } michael@0: michael@0: static float anp_getTextSize(const ANPPaint* paint) { michael@0: return SkScalarToFloat(paint->getTextSize()); michael@0: } michael@0: michael@0: static float anp_getTextScaleX(const ANPPaint* paint) { michael@0: return SkScalarToFloat(paint->getTextScaleX()); michael@0: } michael@0: michael@0: static float anp_getTextSkewX(const ANPPaint* paint) { michael@0: return SkScalarToFloat(paint->getTextSkewX()); michael@0: } michael@0: michael@0: static ANPTypeface* anp_getTypeface(const ANPPaint* paint) { michael@0: return reinterpret_cast(paint->getTypeface()); michael@0: } michael@0: michael@0: static void anp_setTextEncoding(ANPPaint* paint, ANPTextEncoding encoding) { michael@0: paint->setTextEncoding(static_cast(encoding)); michael@0: } michael@0: michael@0: static void anp_setTextAlign(ANPPaint* paint, ANPPaintAlign align) { michael@0: paint->setTextAlign(static_cast(align)); michael@0: } michael@0: michael@0: static void anp_setTextSize(ANPPaint* paint, float textSize) { michael@0: paint->setTextSize(SkFloatToScalar(textSize)); michael@0: } michael@0: michael@0: static void anp_setTextScaleX(ANPPaint* paint, float scaleX) { michael@0: paint->setTextScaleX(SkFloatToScalar(scaleX)); michael@0: } michael@0: michael@0: static void anp_setTextSkewX(ANPPaint* paint, float skewX) { michael@0: paint->setTextSkewX(SkFloatToScalar(skewX)); michael@0: } michael@0: michael@0: static void anp_setTypeface(ANPPaint* paint, ANPTypeface* tf) { michael@0: paint->setTypeface(tf); michael@0: } michael@0: michael@0: static float anp_measureText(ANPPaint* paint, const void* text, michael@0: uint32_t byteLength, ANPRectF* bounds) { michael@0: SkScalar w = paint->measureText(text, byteLength, michael@0: reinterpret_cast(bounds)); michael@0: return SkScalarToFloat(w); michael@0: } michael@0: michael@0: /** Return the number of unichars specifed by the text. michael@0: If widths is not null, returns the array of advance widths for each michael@0: unichar. michael@0: If bounds is not null, returns the array of bounds for each unichar. michael@0: */ michael@0: static int anp_getTextWidths(ANPPaint* paint, const void* text, michael@0: uint32_t byteLength, float widths[], ANPRectF bounds[]) { michael@0: return paint->getTextWidths(text, byteLength, widths, michael@0: reinterpret_cast(bounds)); michael@0: } michael@0: michael@0: static float anp_getFontMetrics(ANPPaint* paint, ANPFontMetrics* metrics) { michael@0: SkPaint::FontMetrics fm; michael@0: SkScalar spacing = paint->getFontMetrics(&fm); michael@0: if (metrics) { michael@0: metrics->fTop = SkScalarToFloat(fm.fTop); michael@0: metrics->fAscent = SkScalarToFloat(fm.fAscent); michael@0: metrics->fDescent = SkScalarToFloat(fm.fDescent); michael@0: metrics->fBottom = SkScalarToFloat(fm.fBottom); michael@0: metrics->fLeading = SkScalarToFloat(fm.fLeading); michael@0: } michael@0: return SkScalarToFloat(spacing); michael@0: } michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: #define ASSIGN(obj, name) (obj)->name = anp_##name michael@0: michael@0: void InitPaintInterface(ANPPaintInterfaceV0* i) { michael@0: ASSIGN(i, newPaint); michael@0: ASSIGN(i, deletePaint); michael@0: ASSIGN(i, getFlags); michael@0: ASSIGN(i, setFlags); michael@0: ASSIGN(i, getColor); michael@0: ASSIGN(i, setColor); michael@0: ASSIGN(i, getStyle); michael@0: ASSIGN(i, setStyle); michael@0: ASSIGN(i, getStrokeWidth); michael@0: ASSIGN(i, getStrokeMiter); michael@0: ASSIGN(i, getStrokeCap); michael@0: ASSIGN(i, getStrokeJoin); michael@0: ASSIGN(i, setStrokeWidth); michael@0: ASSIGN(i, setStrokeMiter); michael@0: ASSIGN(i, setStrokeCap); michael@0: ASSIGN(i, setStrokeJoin); michael@0: ASSIGN(i, getTextEncoding); michael@0: ASSIGN(i, getTextAlign); michael@0: ASSIGN(i, getTextSize); michael@0: ASSIGN(i, getTextScaleX); michael@0: ASSIGN(i, getTextSkewX); michael@0: ASSIGN(i, getTypeface); michael@0: ASSIGN(i, setTextEncoding); michael@0: ASSIGN(i, setTextAlign); michael@0: ASSIGN(i, setTextSize); michael@0: ASSIGN(i, setTextScaleX); michael@0: ASSIGN(i, setTextSkewX); michael@0: ASSIGN(i, setTypeface); michael@0: ASSIGN(i, measureText); michael@0: ASSIGN(i, getTextWidths); michael@0: ASSIGN(i, getFontMetrics); michael@0: }