| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "gm.h" | 8 #include "gm.h" |
| 9 | 9 |
| 10 class SkJSCanvas { | 10 class SkJSCanvas { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 private: | 31 private: |
| 32 SkCanvas* fTarget; | 32 SkCanvas* fTarget; |
| 33 SkPaint fFillPaint; | 33 SkPaint fFillPaint; |
| 34 SkPaint fStrokePaint; | 34 SkPaint fStrokePaint; |
| 35 SkPath fPath; | 35 SkPath fPath; |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 SkJSCanvas::SkJSCanvas(SkCanvas* target) : fTarget(target) { | 38 SkJSCanvas::SkJSCanvas(SkCanvas* target) : fTarget(target) { |
| 39 fFillPaint.setAntiAlias(true); | 39 fFillPaint.setAntiAlias(true); |
| 40 sk_tool_utils::set_portable_typeface(&fFillPaint); | 40 sk_tool_utils::set_portable_typeface_always(&fFillPaint); |
| 41 fStrokePaint.setAntiAlias(true); | 41 fStrokePaint.setAntiAlias(true); |
| 42 fStrokePaint.setStyle(SkPaint::kStroke_Style); | 42 fStrokePaint.setStyle(SkPaint::kStroke_Style); |
| 43 fStrokePaint.setStrokeWidth(SK_Scalar1); | 43 fStrokePaint.setStrokeWidth(SK_Scalar1); |
| 44 } | 44 } |
| 45 | 45 |
| 46 SkJSCanvas::~SkJSCanvas() {} | 46 SkJSCanvas::~SkJSCanvas() {} |
| 47 | 47 |
| 48 void SkJSCanvas::save() { fTarget->save(); } | 48 void SkJSCanvas::save() { fTarget->save(); } |
| 49 void SkJSCanvas::restore() { fTarget->restore(); } | 49 void SkJSCanvas::restore() { fTarget->restore(); } |
| 50 | 50 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 195 |
| 196 for (int i = 0; i < count; i++) { | 196 for (int i = 0; i < count; i++) { |
| 197 src[i].set(SkIntToScalar(isrc[2*i+0]), SkIntToScalar(isrc[2*i+1])); | 197 src[i].set(SkIntToScalar(isrc[2*i+0]), SkIntToScalar(isrc[2*i+1])); |
| 198 dst[i].set(SkIntToScalar(idst[2*i+0]), SkIntToScalar(idst[2*i+1])); | 198 dst[i].set(SkIntToScalar(idst[2*i+0]), SkIntToScalar(idst[2*i+1])); |
| 199 } | 199 } |
| 200 | 200 |
| 201 canvas->save(); | 201 canvas->save(); |
| 202 matrix.setPolyToPoly(src, dst, count); | 202 matrix.setPolyToPoly(src, dst, count); |
| 203 canvas->concat(matrix); | 203 canvas->concat(matrix); |
| 204 | 204 |
| 205 paint->setColor(SK_ColorGRAY); | 205 paint->setColor(sk_tool_utils::color_to_565(SK_ColorGRAY)); |
| 206 paint->setStyle(SkPaint::kStroke_Style); | 206 paint->setStyle(SkPaint::kStroke_Style); |
| 207 const SkScalar D = SkIntToScalar(64); | 207 const SkScalar D = SkIntToScalar(64); |
| 208 canvas->drawRectCoords(0, 0, D, D, *paint); | 208 canvas->drawRectCoords(0, 0, D, D, *paint); |
| 209 canvas->drawLine(0, 0, D, D, *paint); | 209 canvas->drawLine(0, 0, D, D, *paint); |
| 210 canvas->drawLine(0, D, D, 0, *paint); | 210 canvas->drawLine(0, D, D, 0, *paint); |
| 211 | 211 |
| 212 SkPaint::FontMetrics fm; | 212 SkPaint::FontMetrics fm; |
| 213 paint->getFontMetrics(&fm); | 213 paint->getFontMetrics(&fm); |
| 214 paint->setColor(SK_ColorRED); | 214 paint->setColor(SK_ColorRED); |
| 215 paint->setStyle(SkPaint::kFill_Style); | 215 paint->setStyle(SkPaint::kFill_Style); |
| 216 SkScalar x = D/2; | 216 SkScalar x = D/2; |
| 217 SkScalar y = D/2 - (fm.fAscent + fm.fDescent)/2; | 217 SkScalar y = D/2 - (fm.fAscent + fm.fDescent)/2; |
| 218 SkString str; | 218 SkString str; |
| 219 str.appendS32(count); | 219 str.appendS32(count); |
| 220 canvas->drawText(str.c_str(), str.size(), x, y, *paint); | 220 canvas->drawText(str.c_str(), str.size(), x, y, *paint); |
| 221 | 221 |
| 222 canvas->restore(); | 222 canvas->restore(); |
| 223 } | 223 } |
| 224 | 224 |
| 225 void onDraw(SkCanvas* canvas) override { | 225 void onDraw(SkCanvas* canvas) override { |
| 226 if (false) { test_stroke(canvas); return; } | 226 if (false) { test_stroke(canvas); return; } |
| 227 | 227 |
| 228 SkPaint paint; | 228 SkPaint paint; |
| 229 paint.setAntiAlias(true); | 229 paint.setAntiAlias(true); |
| 230 sk_tool_utils::set_portable_typeface(&paint); | 230 sk_tool_utils::set_portable_typeface_always(&paint); |
| 231 paint.setStrokeWidth(SkIntToScalar(4)); | 231 paint.setStrokeWidth(SkIntToScalar(4)); |
| 232 paint.setTextSize(SkIntToScalar(40)); | 232 paint.setTextSize(SkIntToScalar(40)); |
| 233 paint.setTextAlign(SkPaint::kCenter_Align); | 233 paint.setTextAlign(SkPaint::kCenter_Align); |
| 234 | 234 |
| 235 canvas->save(); | 235 canvas->save(); |
| 236 canvas->translate(SkIntToScalar(10), SkIntToScalar(10)); | 236 canvas->translate(SkIntToScalar(10), SkIntToScalar(10)); |
| 237 // translate (1 point) | 237 // translate (1 point) |
| 238 const int src1[] = { 0, 0 }; | 238 const int src1[] = { 0, 0 }; |
| 239 const int dst1[] = { 5, 5 }; | 239 const int dst1[] = { 5, 5 }; |
| 240 doDraw(canvas, &paint, src1, dst1, 1); | 240 doDraw(canvas, &paint, src1, dst1, 1); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 265 canvas->restore(); | 265 canvas->restore(); |
| 266 } | 266 } |
| 267 | 267 |
| 268 private: | 268 private: |
| 269 typedef skiagm::GM INHERITED; | 269 typedef skiagm::GM INHERITED; |
| 270 }; | 270 }; |
| 271 | 271 |
| 272 ////////////////////////////////////////////////////////////////////////////// | 272 ////////////////////////////////////////////////////////////////////////////// |
| 273 | 273 |
| 274 DEF_GM( return new Poly2PolyGM; ) | 274 DEF_GM( return new Poly2PolyGM; ) |
| OLD | NEW |