LMPX.COM |
Home | Linux | Mysql | PHP | XML | ||
|
|
|||
From: Takeshi Abe Date: Mon Jun 30 05:41:04 2008 Subject: cvs: gd /gd-pango gd_pango.c
tabe Mon Jun 30 11:41:04 2008 UTC
Modified files:
/gd/gd-pango gd_pango.c
Log:
* escape in case of non-positive width/height in gdPangoCopyFTBitmapToSurface()
* end became exclusive in gdPangoDrawSpan()
* initialize colors for each run in gdPangoRenderLine()
* calculate rotated brect like gdImageStringFT()
* some cosmetic fixes
http://cvs.php.net/viewvc.cgi/gd/gd-pango/gd_pango.c?r1=1.7&r2=1.8&diff_format=u
Index: gd/gd-pango/gd_pango.c
diff -u gd/gd-pango/gd_pango.c:1.7 gd/gd-pango/gd_pango.c:1.8
--- gd/gd-pango/gd_pango.c:1.7 Tue Jun 24 01:43:19 2008
+++ gd/gd-pango/gd_pango.c Mon Jun 30 11:41:04 2008
@@ -15,7 +15,7 @@
| Authors: Pierre-A. Joye <pierre@php.net> |
+----------------------------------------------------------------------+
*/
-/* $Id: gd_pango.c,v 1.7 2008/06/24 01:43:19 tabe Exp $ */
+/* $Id: gd_pango.c,v 1.8 2008/06/30 11:41:04 tabe Exp $ */
/**
* @file
* @brief Pango support for GD
@@ -24,7 +24,7 @@
*
* @author Pierre-Alain Joye
* @date 2006/12/19
- * $Id: gd_pango.c,v 1.7 2008/06/24 01:43:19 tabe Exp $
+ * $Id: gd_pango.c,v 1.8 2008/06/30 11:41:04 tabe Exp $
*/
/**
* \mainpage
@@ -101,7 +101,7 @@
#include <fontconfig/fontconfig.h>
#include <fontconfig/fcfreetype.h>
-//! non-zero if initialized
+/*! non-zero if initialized */
static int GD_PANGO_IS_INITIALIZED = 0;
static void gdPangoGetItemProperties (
@@ -157,10 +157,10 @@
case PANGO_ATTR_FOREGROUND:
if (fg_color) {
- *fg_color = ((PangoAttrColor *)attr)->color;
+ *fg_color = ((PangoAttrColor *)attr)->color;
}
if (fg_set) {
- *fg_set = TRUE;
+ *fg_set = TRUE;
}
break;
@@ -246,16 +246,16 @@
int color_fg, alpha_blending_back;
if(x + width > surface->sx) {
- width = surface->sx - x;
- if(width <= 0) {
- return;
- }
+ width = surface->sx - x;
+ }
+ if(width <= 0) {
+ return;
}
if(y + height > surface->sy) {
height = surface->sy - y;
- if(height <= 0) {
- return;
- }
+ }
+ if(height <= 0) {
+ return;
}
alpha_blending_back = surface->alphaBlendingFlag;
@@ -318,7 +318,7 @@
end = surface->sx;
}
color = colors->fg;
- for (ix = start; ix <= end; ix++) {
+ for (ix = start; ix < end; ix++) {
gdImageSetPixel(surface, ix, y, color);
}
}
@@ -332,11 +332,11 @@
gint height,
gint baseline)
{
- gdPangoColors colors = context->default_colors;
GSList *tmp_list = line->runs;
int x_off = 0;
while (tmp_list) {
+ gdPangoColors colors = context->default_colors;
PangoLayoutRun *run = tmp_list->data;
PangoUnderline uline = PANGO_UNDERLINE_NONE;
gboolean strike, fg_set, bg_set, shape_set;
@@ -357,7 +357,7 @@
if(fg_set) {
colors.fg = gdPangoColorToRGBA7888(fg_color);
- if(gdTrueColorGetAlpha(colors.bg) == 127) {
+ if(gdTrueColorGetAlpha(colors.bg) == gdAlphaTransparent) {
colors.bg = gdPangoColorToRGBA7888(fg_color);
}
}
@@ -888,22 +888,22 @@
char *gdImageStringPangoFT(gdImagePtr im, int *brect, int fg, char *fontlist,
double ptsize, double angle, int x, int y, char *string)
{
- int w, h;
int r;
+ double angle_d; /* angle in degrees */
gdPangoContext *context;
gdPangoColors default_colors;
PangoContext *pangocontext;
- PangoMatrix affined_matrix = PANGO_MATRIX_INIT;
- PangoLayout *layout;
default_colors.fg = fg;
- default_colors.bg = gdTrueColorAlpha(0, 0, 0, 127);
- default_colors.alpha = 127;
-
+ default_colors.bg = gdTrueColorAlpha(0, 0, 0, gdAlphaTransparent);
+ default_colors.alpha = gdAlphaTransparent;
+
/* gdImageStringFT uses angle in radians */
- angle *= 180 / G_PI;
+ angle_d = (angle / G_PI) * 180;
context = gdPangoCreateContext();
+ pangocontext = gdPangoGetPangoContext(context);
+ pango_context_set_base_dir(pangocontext, PANGO_DIRECTION_LTR);
r = gdPangoSetPangoFontDescriptionFromFile(context, fontlist, ptsize, NULL);
if (r != GD_SUCCESS) {
gdPangoFreeContext(context);
@@ -911,31 +911,47 @@
}
gdPangoSetDefaultColor(context, &default_colors);
gdPangoSetMarkup(context, string, -1);
- pangocontext = gdPangoGetPangoContext(context);
- layout = gdPangoGetPangoLayout(context);
- pango_context_set_base_dir(pangocontext, PANGO_DIRECTION_LTR);
-
- w = gdPangoGetLayoutWidth(context);
- h = gdPangoGetLayoutHeight(context);
-
- brect[0] = x;
- brect[1] = y + h;
- brect[2] = x + w;
- brect[3] = y + h;
- brect[4] = x + w;
- brect[5] = y;
- brect[6] = x;
- brect[7] = y;
- context->angle = angle;
- if (angle != 0.0) {
+ context->angle = angle_d;
+ if (angle != 0.) {
+ PangoMatrix affined_matrix = PANGO_MATRIX_INIT;
+ PangoLayout *layout;
+ layout = gdPangoGetPangoLayout(context);
pango_matrix_rotate(&affined_matrix, context->angle);
pango_context_set_matrix(pangocontext, &affined_matrix);
- pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT);
pango_layout_context_changed(layout);
context->matrix = &affined_matrix;
}
- gdPangoRenderTo(context, im, x, y);
+
+ if (brect) {
+ int w = gdPangoGetLayoutWidth(context);
+ int h = gdPangoGetLayoutHeight(context);
+ if (angle == 0.) {
+ brect[0] = x;
+ brect[1] = y + h;
+ brect[2] = x + w;
+ brect[3] = y + h;
+ brect[4] = x + w;
+ brect[5] = y;
+ } else { /* rotated */
+ double sin_a = sin(angle);
+ double cos_a = cos(angle);
+ int h_sin_a = (int)ceil(h * sin_a);
+ int h_cos_a = (int)ceil(h * cos_a);
+ int w_sin_a = (int)ceil(w * sin_a);
+ int w_cos_a = (int)ceil(w * cos_a);
+ brect[0] = x + h_sin_a;
+ brect[1] = y + h_cos_a;
+ brect[2] = x + h_sin_a + w_cos_a;
+ brect[3] = y + h_cos_a - w_sin_a;
+ brect[4] = x + w_cos_a;
+ brect[5] = y - w_sin_a;
+ }
+ brect[6] = x;
+ brect[7] = y;
+ }
+
+ if (im) gdPangoRenderTo(context, im, x, y);
gdPangoFreeContext(context);
| Navigate in group php.gd.cvs at sever news.php.net | |
| Previous | Next |
| © No Copyright You are free to use Anything |
Site Maintained by PHP Developer
Powered By PHP Consultants |