@Override public float getFontSizePx(Style style) { return style.getFontSize() * displayMetrics.scaledDensity; }
public static int getTypefaceStyle(Style style) { return getTypefaceStyle(style.getFontStyle(), style.getFontVariant(), style.getFontWeight()); }
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()); }
String fontFamily = style.getFontFamily(); int fontSize = Math.round(y_mm2px(style.getFontSize())); Typeface typeface = FontUtils.getTypeface(typefaceMap, fontFamily, style.getFontStyle(), style.getFontVariant(), style.getFontWeight()); if (typeface == null) span = new TextAppearanceSpan(fontFamily, typefaceStyle, fontSize, fontColor, fontLinkColor); fontKey = new FontKey(spans[spanIndex].getStyle().getFontFamily(), typefaces[spanIndex].getStyle(), fontSizes[spanIndex]); spanEnd = spans[spanIndex].getEndPosition(); updatePaint(fontSizes, typefaces, spanIndex); FontKey fontKey = new FontKey(spans[0].getStyle().getFontFamily(), typefaces[0].getStyle(), fontSizes[0]); updatePaint(fontSizes, typefaces, 0); int start = text.getGlyphBeginAt(0);
@Override public Rectangle[] getCharacterBoundingBoxes(Text text, TextSpan[] spans) { GlyphMetrics[] metrics = getGlyphMetrics(text, spans); Rectangle[] charBoxes = new Rectangle[metrics.length]; for (int i = 0; i < charBoxes.length; ++i) charBoxes[i] = new Rectangle(metrics[i].boundingBox); return charBoxes; }
public static Typeface getTypeface(Style style) { return getTypeface(style.getFontFamily(), getTypefaceStyle(style)); }
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 boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if (editor.isScrollAllowed()) { Point oldOffset = editor.getRenderer().getViewOffset(); Point newOffset = new Point(oldOffset.x + distanceX, oldOffset.y + distanceY); editor.clampViewOffset(newOffset); editor.getRenderer().setViewOffset(newOffset.x, newOffset.y); renderTarget.invalidate(editor.getRenderer(), EnumSet.allOf(IRenderTarget.LayerType.class)); return true; } return false; }