Files
android_translation_layer/src/api-impl/android/graphics/Paint.java

229 lines
6.3 KiB
Java
Raw Normal View History

package android.graphics;
public class Paint {
public long skia_paint = 0;
private Typeface typeface = null;
public long skia_font = 0;
ColorFilter colorFilter = null;
public Paint() {
skia_paint = native_constructor();
}
public Paint (int flags) {
this();
setFlags(flags);
}
public Paint(Paint paint) {
/* TODO: use sk_paint_clone */
this();
setColor(paint.getColor());
}
2022-12-27 17:21:21 +01:00
public void setColor(int color) {
native_set_color(skia_paint, color);
}
2022-12-27 17:21:21 +01:00
public int getColor() {
return native_get_color(skia_paint);
}
public void setAntiAlias(boolean aa) {}
public void setStrokeWidth(float width) {}
public void setTextSize(float size) {
if(skia_font == 0)
skia_font = native_create_font();
native_set_text_size(skia_font, size);
}
2022-12-27 17:21:21 +01:00
public Typeface setTypeface(Typeface typeface) {
this.typeface = typeface;
if(skia_font == 0)
skia_font = native_create_font();
if (typeface != null)
native_set_typeface(skia_font, typeface.skia_typeface);
return this.typeface;
}
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) {}
public void setFlags(int flags) {}
public void setFilterBitmap(boolean filter) {}
2022-12-27 17:21:21 +01:00
public void setStyle(Style style) {}
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; }
public float measureText(String text) {
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; }
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.
*/
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.
*/
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.
*/
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 {
/**
* 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.
*/
public float top;
2022-12-27 17:21:21 +01:00
/**
* The recommended distance above the baseline for singled spaced text.
*/
public float ascent;
2022-12-27 17:21:21 +01:00
/**
* The recommended distance below the baseline for singled spaced text.
*/
public float descent;
2022-12-27 17:21:21 +01: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.
*/
public float bottom;
2022-12-27 17:21:21 +01:00
/**
* The recommended additional space to add between lines of text.
*/
public float leading;
2022-12-27 17:21:21 +01:00
}
public static class FontMetricsInt {
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 +
" descent=" + descent + " bottom=" + bottom +
" leading=" + leading;
2022-12-27 17:21:21 +01:00
}
}
public /*native*/ int getFlags() { return 0; }
2022-12-27 17:21:21 +01: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) {}
public /*native*/ int getAlpha() { return 0; }
2022-12-27 17:21:21 +01:00
public /*native*/ void setAlpha(int a) {}
public /*native*/ float getStrokeWidth() { return 0; }
2022-12-27 17:21:21 +01:00
public /*native*/ float getStrokeMiter() { return 0; }
2022-12-27 17:21:21 +01:00
public /*native*/ void setStrokeMiter(float miter) {}
public /*native*/ float getTextSize() { return 0; }
2022-12-27 17:21:21 +01:00
public /*native*/ float getTextScaleX() { return 0; }
2022-12-27 17:21:21 +01:00
public /*native*/ void setTextScaleX(float scaleX) {}
public /*native*/ float getTextSkewX() { return 0; }
2022-12-27 17:21:21 +01:00
public /*native*/ void setTextSkewX(float skewX) {}
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) {}
public Xfermode setXfermode(Xfermode xfermode) { return xfermode; }
2023-01-14 14:32:37 +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.
*/
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.
*/
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.
*/
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
*/
MITER(0),
2023-01-14 14:32:37 +01:00
/**
* The outer edges of a join meet in a circular arc.
*/
ROUND(1),
2023-01-14 14:32:37 +01:00
/**
* The outer edges of a join meet with a straight line
*/
BEVEL(2);
2023-01-14 14:32:37 +01:00
private Join(int nativeInt) {}
}
public void setStrokeCap(Cap cap) {}
2023-01-14 14:32:37 +01:00
public void setStrokeJoin(Join join) {}
2023-09-19 23:22:21 +02:00
public Typeface getTypeface() {
return new Typeface();
}
private native long native_constructor();
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);
}