2022-10-02 23:06:56 +02:00
|
|
|
package android.graphics;
|
|
|
|
|
|
|
|
|
|
public class Paint {
|
2024-04-09 18:58:05 +02:00
|
|
|
public static final int ANTI_ALIAS_FLAG = (1 << 0);
|
|
|
|
|
public static final int FILTER_BITMAP_FLAG = (1 << 1);
|
|
|
|
|
public static final int DITHER_FLAG = (1 << 2);
|
|
|
|
|
public static final int UNDERLINE_TEXT_FLAG = (1 << 3);
|
|
|
|
|
public static final int STRIKE_THRU_TEXT_FLAG = (1 << 4);
|
|
|
|
|
public static final int FAKE_BOLD_TEXT_FLAG = (1 << 5);
|
|
|
|
|
public static final int LINEAR_TEXT_FLAG = (1 << 6);
|
|
|
|
|
public static final int SUBPIXEL_TEXT_FLAG = (1 << 7);
|
|
|
|
|
public static final int DEV_KERN_TEXT_FLAG = (1 << 8);
|
|
|
|
|
public static final int LCD_RENDER_TEXT_FLAG = (1 << 9);
|
|
|
|
|
public static final int EMBEDDED_BITMAP_TEXT_FLAG = (1 << 10);
|
|
|
|
|
public static final int AUTO_HINTING_TEXT_FLAG = (1 << 11);
|
|
|
|
|
public static final int VERTICAL_TEXT_FLAG = (1 << 12);
|
|
|
|
|
|
2023-09-12 19:30:20 +02:00
|
|
|
public long skia_paint = 0;
|
|
|
|
|
private Typeface typeface = null;
|
|
|
|
|
public long skia_font = 0;
|
2024-03-24 21:12:13 +01:00
|
|
|
ColorFilter colorFilter = null;
|
2022-10-02 23:06:56 +02:00
|
|
|
|
2023-08-17 10:46:24 +02:00
|
|
|
public Paint() {
|
2023-08-28 20:03:32 +02:00
|
|
|
skia_paint = native_constructor();
|
2023-08-17 10:46:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Paint (int flags) {
|
|
|
|
|
this();
|
|
|
|
|
setFlags(flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Paint(Paint paint) {
|
2023-08-28 20:03:32 +02:00
|
|
|
/* TODO: use sk_paint_clone */
|
|
|
|
|
this();
|
2023-08-17 10:46:24 +02:00
|
|
|
setColor(paint.getColor());
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-27 17:21:21 +01:00
|
|
|
public void setColor(int color) {
|
2023-08-28 20:03:32 +02:00
|
|
|
native_set_color(skia_paint, color);
|
2022-10-02 23:06:56 +02:00
|
|
|
}
|
|
|
|
|
|
2022-12-27 17:21:21 +01:00
|
|
|
public int getColor() {
|
2023-08-28 20:03:32 +02:00
|
|
|
return native_get_color(skia_paint);
|
2022-10-02 23:06:56 +02:00
|
|
|
}
|
|
|
|
|
|
2024-04-09 18:58:05 +02:00
|
|
|
public void setAntiAlias(boolean aa) {
|
|
|
|
|
native_set_antialias(skia_paint, aa);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-08 23:15:05 +02:00
|
|
|
public void setStrokeWidth(float width) {
|
|
|
|
|
native_set_stroke_width(skia_paint, width);
|
|
|
|
|
}
|
2023-09-12 19:30:20 +02:00
|
|
|
public void setTextSize(float size) {
|
|
|
|
|
if(skia_font == 0)
|
|
|
|
|
skia_font = native_create_font();
|
|
|
|
|
|
|
|
|
|
native_set_text_size(skia_font, size);
|
|
|
|
|
}
|
2022-10-02 23:06:56 +02:00
|
|
|
|
2022-12-27 17:21:21 +01:00
|
|
|
public Typeface setTypeface(Typeface typeface) {
|
2023-09-12 19:30:20 +02:00
|
|
|
this.typeface = typeface;
|
|
|
|
|
if(skia_font == 0)
|
|
|
|
|
skia_font = native_create_font();
|
|
|
|
|
|
2023-10-14 11:13:10 +02:00
|
|
|
if (typeface != null)
|
|
|
|
|
native_set_typeface(skia_font, typeface.skia_typeface);
|
2023-09-12 19:30:20 +02:00
|
|
|
return this.typeface;
|
2022-10-02 23:06:56 +02:00
|
|
|
}
|
2022-12-27 17:21:21 +01:00
|
|
|
public void getTextBounds(String text, int start, int end, Rect bounds) {}
|
|
|
|
|
public void getTextBounds(char[] text, int index, int count, Rect bounds) {}
|
2024-11-01 14:21:15 +01:00
|
|
|
public int getTextWidths(String text, int start, int end, float[] widths) {
|
|
|
|
|
// TODO fix it
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2022-10-02 23:06:56 +02:00
|
|
|
public void setFilterBitmap(boolean filter) {}
|
2024-04-09 18:58:05 +02:00
|
|
|
|
|
|
|
|
public void setFlags(int flags) {
|
|
|
|
|
if((flags & ANTI_ALIAS_FLAG) != 0)
|
|
|
|
|
setAntiAlias(true);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-08 23:15:05 +02:00
|
|
|
public void setStyle(Style style) {
|
|
|
|
|
native_set_style(skia_paint, style.nativeInt);
|
|
|
|
|
}
|
2024-04-09 18:58:05 +02:00
|
|
|
|
2023-09-12 19:30:20 +02:00
|
|
|
public float ascent() {
|
|
|
|
|
if(skia_font == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
return native_ascent(skia_font);
|
|
|
|
|
}
|
2022-12-27 17:21:21 +01:00
|
|
|
|
|
|
|
|
public float measureText(char[] text, int index, int count) { return 10; }
|
|
|
|
|
public float measureText(String text, int start, int end) { return 10; }
|
2023-09-12 19:30:20 +02:00
|
|
|
public float measureText(String text) {
|
2024-06-15 22:32:01 +02:00
|
|
|
if (skia_font == 0)
|
|
|
|
|
skia_font = native_create_font();
|
2023-09-12 19:30:20 +02:00
|
|
|
return native_measure_text(skia_font, text, 0, text.length(), skia_paint);
|
|
|
|
|
}
|
2022-12-27 17:21:21 +01:00
|
|
|
public float measureText(CharSequence text, int start, int end) { return 10; }
|
|
|
|
|
|
2024-03-24 21:12:13 +01:00
|
|
|
public ColorFilter setColorFilter(ColorFilter colorFilter) {
|
|
|
|
|
this.colorFilter = colorFilter;
|
|
|
|
|
return colorFilter;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-24 20:43:47 +01:00
|
|
|
public Shader setShader(Shader shader) { return shader; }
|
|
|
|
|
|
2022-12-27 17:21:21 +01:00
|
|
|
public enum Style {
|
|
|
|
|
/**
|
|
|
|
|
* Geometry and text drawn with this style will be filled, ignoring all
|
|
|
|
|
* stroke-related settings in the paint.
|
|
|
|
|
*/
|
2023-06-22 11:45:46 +02:00
|
|
|
FILL(0),
|
2022-12-27 17:21:21 +01:00
|
|
|
/**
|
|
|
|
|
* Geometry and text drawn with this style will be stroked, respecting
|
|
|
|
|
* the stroke-related fields on the paint.
|
|
|
|
|
*/
|
2023-06-22 11:45:46 +02:00
|
|
|
STROKE(1),
|
2022-12-27 17:21:21 +01:00
|
|
|
/**
|
|
|
|
|
* Geometry and text drawn with this style will be both filled and
|
|
|
|
|
* stroked at the same time, respecting the stroke-related fields on
|
|
|
|
|
* the paint. This mode can give unexpected results if the geometry
|
|
|
|
|
* is oriented counter-clockwise. This restriction does not apply to
|
|
|
|
|
* either FILL or STROKE.
|
|
|
|
|
*/
|
2023-06-22 11:45:46 +02:00
|
|
|
FILL_AND_STROKE(2);
|
|
|
|
|
|
2022-12-27 17:21:21 +01:00
|
|
|
Style(int nativeInt) {
|
|
|
|
|
this.nativeInt = nativeInt;
|
|
|
|
|
}
|
|
|
|
|
final int nativeInt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class FontMetrics {
|
|
|
|
|
/**
|
2023-06-22 11:45:46 +02:00
|
|
|
* The maximum distance above the baseline for the tallest glyph in
|
2022-12-27 17:21:21 +01:00
|
|
|
* the font at a given text size.
|
|
|
|
|
*/
|
2023-06-22 11:45:46 +02:00
|
|
|
public float top;
|
2022-12-27 17:21:21 +01:00
|
|
|
/**
|
|
|
|
|
* The recommended distance above the baseline for singled spaced text.
|
|
|
|
|
*/
|
2023-06-22 11:45:46 +02:00
|
|
|
public float ascent;
|
2022-12-27 17:21:21 +01:00
|
|
|
/**
|
|
|
|
|
* The recommended distance below the baseline for singled spaced text.
|
|
|
|
|
*/
|
2023-06-22 11:45:46 +02:00
|
|
|
public float descent;
|
2022-12-27 17:21:21 +01:00
|
|
|
/**
|
2023-06-22 11:45:46 +02:00
|
|
|
* The maximum distance below the baseline for the lowest glyph in
|
2022-12-27 17:21:21 +01:00
|
|
|
* the font at a given text size.
|
|
|
|
|
*/
|
2023-06-22 11:45:46 +02:00
|
|
|
public float bottom;
|
2022-12-27 17:21:21 +01:00
|
|
|
/**
|
|
|
|
|
* The recommended additional space to add between lines of text.
|
|
|
|
|
*/
|
2023-06-22 11:45:46 +02:00
|
|
|
public float leading;
|
2022-12-27 17:21:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class FontMetricsInt {
|
2023-06-22 11:45:46 +02:00
|
|
|
public int top;
|
|
|
|
|
public int ascent;
|
|
|
|
|
public int descent;
|
|
|
|
|
public int bottom;
|
|
|
|
|
public int leading;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String toString() {
|
2022-12-27 17:21:21 +01:00
|
|
|
return "FontMetricsInt: top=" + top + " ascent=" + ascent +
|
2023-06-22 11:45:46 +02:00
|
|
|
" descent=" + descent + " bottom=" + bottom +
|
|
|
|
|
" leading=" + leading;
|
2022-12-27 17:21:21 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
public /*native*/ int getFlags() { return 0; }
|
2022-12-27 17:21:21 +01:00
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
public /*native*/ int getHinting() { return 0; }
|
2022-12-27 17:21:21 +01:00
|
|
|
public /*native*/ void setHinting(int mode) {}
|
|
|
|
|
|
|
|
|
|
public /*native*/ void setDither(boolean dither) {}
|
|
|
|
|
public /*native*/ void setLinearText(boolean linearText) {}
|
|
|
|
|
public /*native*/ void setSubpixelText(boolean subpixelText) {}
|
|
|
|
|
public /*native*/ void setUnderlineText(boolean underlineText) {}
|
|
|
|
|
public /*native*/ void setStrikeThruText(boolean strikeThruText) {}
|
|
|
|
|
public /*native*/ void setFakeBoldText(boolean fakeBoldText) {}
|
|
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
public /*native*/ int getAlpha() { return 0; }
|
2022-12-27 17:21:21 +01:00
|
|
|
public /*native*/ void setAlpha(int a) {}
|
2023-06-22 11:45:46 +02:00
|
|
|
public /*native*/ float getStrokeWidth() { return 0; }
|
2022-12-27 17:21:21 +01:00
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
public /*native*/ float getStrokeMiter() { return 0; }
|
2022-12-27 17:21:21 +01:00
|
|
|
public /*native*/ void setStrokeMiter(float miter) {}
|
2023-06-22 11:45:46 +02:00
|
|
|
public /*native*/ float getTextSize() { return 0; }
|
2022-12-27 17:21:21 +01:00
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
public /*native*/ float getTextScaleX() { return 0; }
|
2022-12-27 17:21:21 +01:00
|
|
|
public /*native*/ void setTextScaleX(float scaleX) {}
|
2023-06-22 11:45:46 +02:00
|
|
|
public /*native*/ float getTextSkewX() { return 0; }
|
2022-12-27 17:21:21 +01:00
|
|
|
public /*native*/ void setTextSkewX(float skewX) {}
|
|
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
public /*native*/ float descent() { return 0; }
|
|
|
|
|
public /*native*/ float getFontMetrics(FontMetrics metrics) { return 0; }
|
|
|
|
|
public /*native*/ int getFontMetricsInt(FontMetricsInt fmi) { return 0; }
|
2022-12-27 17:21:21 +01:00
|
|
|
|
2023-01-14 14:32:37 +01:00
|
|
|
public void setShadowLayer(float radius, float dx, float dy, int color) {}
|
|
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
public Xfermode setXfermode(Xfermode xfermode) { return xfermode; }
|
2023-01-14 14:32:37 +01:00
|
|
|
|
2023-11-03 18:23:20 +01:00
|
|
|
public void setLetterSpacing(float spacing) {}
|
|
|
|
|
|
2023-01-14 14:32:37 +01:00
|
|
|
public enum Cap {
|
|
|
|
|
/**
|
|
|
|
|
* The stroke ends with the path, and does not project beyond it.
|
|
|
|
|
*/
|
2023-06-22 11:45:46 +02:00
|
|
|
BUTT(0),
|
2023-01-14 14:32:37 +01:00
|
|
|
/**
|
|
|
|
|
* The stroke projects out as a semicircle, with the center at the
|
|
|
|
|
* end of the path.
|
|
|
|
|
*/
|
2023-06-22 11:45:46 +02:00
|
|
|
ROUND(1),
|
2023-01-14 14:32:37 +01:00
|
|
|
/**
|
|
|
|
|
* The stroke projects out as a square, with the center at the end
|
|
|
|
|
* of the path.
|
|
|
|
|
*/
|
2023-06-22 11:45:46 +02:00
|
|
|
SQUARE(2);
|
2023-01-14 14:32:37 +01:00
|
|
|
|
|
|
|
|
private Cap(int nativeInt) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum Join {
|
|
|
|
|
/**
|
|
|
|
|
* The outer edges of a join meet at a sharp angle
|
|
|
|
|
*/
|
2023-06-22 11:45:46 +02:00
|
|
|
MITER(0),
|
2023-01-14 14:32:37 +01:00
|
|
|
/**
|
|
|
|
|
* The outer edges of a join meet in a circular arc.
|
|
|
|
|
*/
|
2023-06-22 11:45:46 +02:00
|
|
|
ROUND(1),
|
2023-01-14 14:32:37 +01:00
|
|
|
/**
|
|
|
|
|
* The outer edges of a join meet with a straight line
|
|
|
|
|
*/
|
2023-06-22 11:45:46 +02:00
|
|
|
BEVEL(2);
|
2023-01-14 14:32:37 +01:00
|
|
|
|
|
|
|
|
private Join(int nativeInt) {}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-29 23:56:28 +01:00
|
|
|
public enum Align {
|
|
|
|
|
CENTER,
|
|
|
|
|
LEFT,
|
|
|
|
|
RIGHT,
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
public void setStrokeCap(Cap cap) {}
|
2023-01-14 14:32:37 +01:00
|
|
|
|
|
|
|
|
public void setStrokeJoin(Join join) {}
|
2023-09-12 19:30:20 +02:00
|
|
|
|
2023-09-19 23:22:21 +02:00
|
|
|
public Typeface getTypeface() {
|
|
|
|
|
return new Typeface();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-29 23:56:28 +01:00
|
|
|
public void setTextAlign(Align align) {}
|
|
|
|
|
|
|
|
|
|
public Shader getShader() {
|
|
|
|
|
return new Shader();
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-12 18:32:30 +02:00
|
|
|
public PathEffect setPathEffect(PathEffect effect) {
|
|
|
|
|
return effect;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int breakText(char[] text, int index, int count, float maxWidth, float[] measuredWidth) { return 10; }
|
|
|
|
|
public int breakText(String text, boolean measureForwards, float maxWidth, float[] measuredWidth) { return 10; }
|
|
|
|
|
public int breakText(CharSequence text, int start, int end, boolean measureForwards, float maxWidth, float[] measuredWidth) { return 10; }
|
|
|
|
|
|
|
|
|
|
public void clearShadowLayer() {}
|
|
|
|
|
|
2024-05-23 22:14:30 +02:00
|
|
|
public FontMetrics getFontMetrics() {
|
|
|
|
|
return new FontMetrics();
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-24 18:44:31 +02:00
|
|
|
public void setFontMetricsInt(FontMetricsInt fmi) {}
|
|
|
|
|
|
|
|
|
|
public FontMetricsInt getFontMetricsInt() {
|
|
|
|
|
return new FontMetricsInt();
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-12 19:30:20 +02:00
|
|
|
private native long native_constructor();
|
2024-04-09 18:58:05 +02:00
|
|
|
private native void native_set_antialias(long skia_paint, boolean aa);
|
2023-09-12 19:30:20 +02:00
|
|
|
private native void native_set_color(long skia_paint, int color);
|
|
|
|
|
private native int native_get_color(long skia_paint);
|
|
|
|
|
private static native long native_create_font();
|
|
|
|
|
private static native float native_ascent(long skia_font);
|
|
|
|
|
private static native void native_set_typeface(long skia_font, long skia_typeface);
|
|
|
|
|
private static native void native_set_text_size(long skia_font, float size);
|
|
|
|
|
private static native float native_measure_text(long skia_font, CharSequence text, int start, int end, long skia_paint);
|
2024-04-08 23:15:05 +02:00
|
|
|
private static native void native_set_stroke_width(long skia_font, float width);
|
|
|
|
|
private static native void native_set_style(long skia_paint, int style);
|
2022-10-02 23:06:56 +02:00
|
|
|
}
|