Implement Bitmap.copy, text layouting (#1455)

* Bitmap: Use provided config

* Bitmap: implement copy

* Bitmap: Simplify getPixels

This also fixes a bug where the returned data may not be in the correct
format

Android getPixels():
> The returned colors are non-premultiplied ARGB values in the sRGB color space.
BufferedImage getRGB():
> Returns an array of integer pixels in the default RGB color model (TYPE_INT_ARGB) and default sRGB color space

* Stub TextPaint and Paint

* Paint: Implement some required functions

* Stub StaticLayout and Layout

* Implement some Paint support

* Draw Bounds

* WebP write support

* First text rendering

* Paint: Fix text size, font metrics

* Paint: Fix not copying new properties

Fixes font size in draw

* Canvas: Stroke add cap/join for better aliasing

Otherwise we get bad artifacts on sharp corners

Based on https://stackoverflow.com/a/35222059/

* Remove logs

* Canvas: Implement other drawText methods

* Bitmap: support erase

* Layout: Fix text direction

Should be LTR, otherwise 0 is read, which is automatically interpreted
as RTL without explicit check

* Bitmap: scale to destination rectangle

* Canvas: drawBitmap with just x/y

* Bitmap: Convert image on JPEG export to RGB

JPEG does not support alpha, so will throw "bogus color space"

* Switch to newer fork
This commit is contained in:
Constantin Piber
2025-06-21 18:01:56 +02:00
committed by GitHub
parent 0b021e6c42
commit 20c850c10b
17 changed files with 7290 additions and 26 deletions
@@ -0,0 +1,74 @@
/*
* Copyright (C) 2006 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.text;
import android.annotation.ColorInt;
import android.graphics.Paint;
public class TextPaint extends Paint {
// Special value 0 means no background paint
@ColorInt
public int bgColor;
public int baselineShift;
@ColorInt
public int linkColor;
public int[] drawableState;
public float density = 1.0f;
@ColorInt
public int underlineColor = 0;
public float underlineThickness;
public TextPaint() {
super();
}
public TextPaint(int flags) {
super(flags);
}
public TextPaint(Paint p) {
super(p);
}
public void set(TextPaint tp) {
super.set(tp);
bgColor = tp.bgColor;
baselineShift = tp.baselineShift;
linkColor = tp.linkColor;
drawableState = tp.drawableState;
density = tp.density;
underlineColor = tp.underlineColor;
underlineThickness = tp.underlineThickness;
}
public void setUnderlineText(int color, float thickness) {
underlineColor = color;
underlineThickness = thickness;
}
@Override
public float getUnderlineThickness() {
if (underlineColor != 0) { // Return custom thickness only if underline color is set.
return underlineThickness;
} else {
return super.getUnderlineThickness();
}
}
}