android/source/src/java/org/libreoffice/canvas/CalcHeaderCell.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
New commits: commit f4d9f597d1192a688900fda7f11f75c5804196ce Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Mon Nov 27 10:55:51 2023 +0100 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Wed Nov 29 13:42:45 2023 +0100 tdf#158398 android: Center Calc header text Center the header text in the Calc header cell, to make better use of the space. This is in line with what the desktop version also does. Setting the text alignment to `Paint.Align.CENTER` is sufficient for centering horizontally. There's no equivalent for centering vertically, so calculate the position based on the text bounds. Change-Id: Ia8d5d8434b703cb7daecd34ae70405883f22f0d5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159988 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160025 diff --git a/android/source/src/java/org/libreoffice/canvas/CalcHeaderCell.java b/android/source/src/java/org/libreoffice/canvas/CalcHeaderCell.java index 1b2db6f65796..eec0b5e4a88d 100644 --- a/android/source/src/java/org/libreoffice/canvas/CalcHeaderCell.java +++ b/android/source/src/java/org/libreoffice/canvas/CalcHeaderCell.java @@ -4,6 +4,7 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; +import android.graphics.Rect; import android.graphics.RectF; import android.text.TextPaint; @@ -11,6 +12,7 @@ public class CalcHeaderCell extends CommonCanvasElement { private final TextPaint mTextPaint = new TextPaint(); private final Paint mBgPaint = new Paint(); private final RectF mBounds; + private final Rect mTextBounds = new Rect(); private final String mText; public CalcHeaderCell(float left, float top, float width, float height, String text, boolean selected) { @@ -26,7 +28,10 @@ public class CalcHeaderCell extends CommonCanvasElement { mBgPaint.setAlpha(100); // hard coded for now mTextPaint.setColor(Color.GRAY); mTextPaint.setTextSize(24f); // hard coded for now + mTextPaint.setTextAlign(Paint.Align.CENTER); mText = text; + + mTextPaint.getTextBounds(mText, 0, mText.length(), mTextBounds); } /** @@ -49,6 +54,6 @@ public class CalcHeaderCell extends CommonCanvasElement { @Override public void onDraw(Canvas canvas) { canvas.drawRect(mBounds, mBgPaint); - canvas.drawText(mText, mBounds.left, mBounds.bottom, mTextPaint); + canvas.drawText(mText, mBounds.centerX(), mBounds.centerY() - mTextBounds.centerY(), mTextPaint); } }