From 6d8225b7bdbbef01e491784025a31254606ce627 Mon Sep 17 00:00:00 2001 From: seanlin Date: Mon, 19 Sep 2011 16:47:39 +0800 Subject: [PATCH] fixed #724, different results of CCLabelTTF on android & win32 --- .../android/src/org/cocos2dx/lib/Cocos2dxBitmap.java | 9 ++++++--- .../android/src/org/cocos2dx/lib/Cocos2dxBitmap.java | 9 ++++++--- .../src/org/cocos2dx/lib/Cocos2dxBitmap.java | 9 ++++++--- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/HelloLua/android/src/org/cocos2dx/lib/Cocos2dxBitmap.java b/HelloLua/android/src/org/cocos2dx/lib/Cocos2dxBitmap.java index c823d3be82..d03a8b6730 100644 --- a/HelloLua/android/src/org/cocos2dx/lib/Cocos2dxBitmap.java +++ b/HelloLua/android/src/org/cocos2dx/lib/Cocos2dxBitmap.java @@ -63,16 +63,19 @@ public class Cocos2dxBitmap{ Paint paint = newPaint(fontName, fontSize, alignment); TextProperty textProperty = computeTextProperty(content, paint, width, height); - + + int BitMapTotalHeight = (height == 0 ? textProperty.totalHeight:height); + // Draw text to bitmap Bitmap bitmap = Bitmap.createBitmap(textProperty.maxWidth, - textProperty.totalHeight, Bitmap.Config.ARGB_8888); + BitMapTotalHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); // Draw string FontMetricsInt fm = paint.getFontMetricsInt(); int x = 0; - int y = -fm.ascent; + int y = height == 0 ?(-fm.ascent): + (-fm.ascent + (height - textProperty.totalHeight)/2); String[] lines = textProperty.lines; for (String line : lines){ x = computeX(paint, line, textProperty.maxWidth, alignment); diff --git a/HelloWorld/android/src/org/cocos2dx/lib/Cocos2dxBitmap.java b/HelloWorld/android/src/org/cocos2dx/lib/Cocos2dxBitmap.java index c823d3be82..d03a8b6730 100644 --- a/HelloWorld/android/src/org/cocos2dx/lib/Cocos2dxBitmap.java +++ b/HelloWorld/android/src/org/cocos2dx/lib/Cocos2dxBitmap.java @@ -63,16 +63,19 @@ public class Cocos2dxBitmap{ Paint paint = newPaint(fontName, fontSize, alignment); TextProperty textProperty = computeTextProperty(content, paint, width, height); - + + int BitMapTotalHeight = (height == 0 ? textProperty.totalHeight:height); + // Draw text to bitmap Bitmap bitmap = Bitmap.createBitmap(textProperty.maxWidth, - textProperty.totalHeight, Bitmap.Config.ARGB_8888); + BitMapTotalHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); // Draw string FontMetricsInt fm = paint.getFontMetricsInt(); int x = 0; - int y = -fm.ascent; + int y = height == 0 ?(-fm.ascent): + (-fm.ascent + (height - textProperty.totalHeight)/2); String[] lines = textProperty.lines; for (String line : lines){ x = computeX(paint, line, textProperty.maxWidth, alignment); diff --git a/tests/test.android/src/org/cocos2dx/lib/Cocos2dxBitmap.java b/tests/test.android/src/org/cocos2dx/lib/Cocos2dxBitmap.java index c823d3be82..d03a8b6730 100644 --- a/tests/test.android/src/org/cocos2dx/lib/Cocos2dxBitmap.java +++ b/tests/test.android/src/org/cocos2dx/lib/Cocos2dxBitmap.java @@ -63,16 +63,19 @@ public class Cocos2dxBitmap{ Paint paint = newPaint(fontName, fontSize, alignment); TextProperty textProperty = computeTextProperty(content, paint, width, height); - + + int BitMapTotalHeight = (height == 0 ? textProperty.totalHeight:height); + // Draw text to bitmap Bitmap bitmap = Bitmap.createBitmap(textProperty.maxWidth, - textProperty.totalHeight, Bitmap.Config.ARGB_8888); + BitMapTotalHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); // Draw string FontMetricsInt fm = paint.getFontMetricsInt(); int x = 0; - int y = -fm.ascent; + int y = height == 0 ?(-fm.ascent): + (-fm.ascent + (height - textProperty.totalHeight)/2); String[] lines = textProperty.lines; for (String line : lines){ x = computeX(paint, line, textProperty.maxWidth, alignment);