mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 23:39:08 +02:00
LCL-CustomDrawn-Android: Improves the text measuring code so that now white space is correctly handled in TEdit
git-svn-id: trunk@37294 -
This commit is contained in:
parent
6523578777
commit
9990ed11e7
@ -330,11 +330,15 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
|
|||||||
{
|
{
|
||||||
Paint localpaint = new Paint();
|
Paint localpaint = new Paint();
|
||||||
Rect localbounds = new Rect();
|
Rect localbounds = new Rect();
|
||||||
|
String lcltext_hack = "M" + lcltext + "M";
|
||||||
localpaint.setTextSize(lcltextsize);
|
localpaint.setTextSize(lcltextsize);
|
||||||
localpaint.getTextBounds(lcltext, 0, lcltext.length(), localbounds);
|
// Paint.getTextBounds has multiple problems:
|
||||||
lclwidth = localbounds.width();
|
// 1->It consistently gives us a too small size
|
||||||
// Painter.getTextBounds consistently gives us a too small size, so work around that
|
// 2->It ignores spaces in the end and has issues with some characters, see http://code.google.com/p/android/issues/detail?id=7527
|
||||||
lclwidth = lclwidth + (3 * lcltextsize) / 16;
|
// so we use measureText instead, but it also has problem 2, so we need to add a character to the start and end of text and then subtract it =(
|
||||||
|
lclwidth = (int) (localpaint.measureText(lcltext_hack) - localpaint.measureText("MM"));
|
||||||
|
// Painter.getTextBounds consistently gives us a too small size so work around that
|
||||||
|
// lclwidth = lclwidth + (3 * lcltextsize) / 16;
|
||||||
// Don't use just localbounds.height() from the source text
|
// Don't use just localbounds.height() from the source text
|
||||||
// because it will calculate the minimum necessary height,
|
// because it will calculate the minimum necessary height,
|
||||||
// but we can't easily use that to draw text because it draws relative to the baseline
|
// but we can't easily use that to draw text because it draws relative to the baseline
|
||||||
|
Loading…
Reference in New Issue
Block a user