@Override protected void onSizeChanged(int newWidth, int newHeight, int oldWidth, int oldHeight) { if (bitmap != null) { bitmap.recycle(); } bitmap = Bitmap.createBitmap(newWidth, newHeight, Bitmap.Config.ARGB_8888); sysCanvas = new android.graphics.Canvas(bitmap); iinkCanvas = new Canvas(sysCanvas, typefaceMap, imageLoader, renderTarget); super.onSizeChanged(newWidth, newHeight, oldWidth, oldHeight); }
@Override public void setStrokeColor(@NonNull Color strokeColor) { strokePaint.setColor(argb(strokeColor)); }
private void applyStyle(@NonNull Style style) { setStrokeColor(style.getStrokeColor()); setStrokeWidth(style.getStrokeWidth()); setStrokeLineCap(style.getStrokeLineCap()); setStrokeLineJoin(style.getStrokeLineJoin()); setStrokeMiterLimit(style.getStrokeMiterLimit()); setStrokeDashArray(style.getStrokeDashArray()); setStrokeDashOffset(style.getStrokeDashOffset()); setFillColor(style.getFillColor()); setFillRule(style.getFillRule()); setFontProperties(style.getFontFamily(), style.getFontLineHeight(), style.getFontSize(), style.getFontStyle(), style.getFontVariant(), style.getFontWeight()); }
public Canvas(@NonNull android.graphics.Canvas canvas, Map<String, Typeface> typefaceMap, ImageLoader imageLoader, IRenderTarget target) { this.canvas = canvas; this.typefaceMap = typefaceMap; this.imageLoader = imageLoader; this.target = target; clips = new HashSet<>(); strokePaint = new Paint(Paint.ANTI_ALIAS_FLAG); strokePaint.setStyle(Paint.Style.STROKE); textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); fillPaint = new Paint(Paint.ANTI_ALIAS_FLAG); fillPaint.setStyle(Paint.Style.FILL); transform = new Transform(); transformMatrix = new Matrix(); transformValues = new float[9]; transformValues[Matrix.MPERSP_0] = 0; transformValues[Matrix.MPERSP_1] = 0; transformValues[Matrix.MPERSP_2] = 1; dashArray = null; displayMetrics = Resources.getSystem().getDisplayMetrics(); textScaleMatrix = new Matrix(); textScaleMatrix.setScale(25.4f / displayMetrics.xdpi, 25.4f / displayMetrics.ydpi); pointScaleMatrix = new Matrix(); textScaleMatrix.invert(pointScaleMatrix); // it is mandatory to configure the Paint with SVG defaults represented by default Style object applyStyle(DEFAULT_SVG_STYLE); }
@Override public void invalidate(Renderer renderer, int x, int y, int width, int height, EnumSet<LayerType> layers) { if (canvas == null) return; canvas.drawARGB(Color.alpha(backgroundColor), Color.red(backgroundColor), Color.green(backgroundColor), Color.blue(backgroundColor)); Canvas androidCanvas = new Canvas(canvas, typefaceMap, imageLoader, this); if (layers.contains(LayerType.MODEL)) renderer.drawModel(x, y, width, height, androidCanvas); if (layers.contains(LayerType.TEMPORARY)) renderer.drawTemporaryItems(x, y, width, height, androidCanvas); if (layers.contains(LayerType.CAPTURE)) renderer.drawCaptureStrokes(x, y, width, height, androidCanvas); }
@Override public void setFillColor(@NonNull Color fillColor) { @ColorInt int color = argb(fillColor); textPaint.setColor(color); fillPaint.setColor(color); }