mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 12:28:22 +01:00
fix bugs
This commit is contained in:
@@ -36,6 +36,7 @@ typedef struct __FreeTypeData{
|
||||
FT_Face face;
|
||||
RColor color;
|
||||
WMFreeTypeRImage **glyphs_array;
|
||||
WMFreeTypeRImage **glyphs_shadow_array;
|
||||
/* will use this when we have frame window plugin */
|
||||
/* char *last_titlestr; */
|
||||
} WMFreeTypeData;
|
||||
@@ -58,6 +59,11 @@ initDrawPlainString(Display *dpy, Colormap cmap) {
|
||||
ds_cmap = cmap;
|
||||
}
|
||||
|
||||
void
|
||||
destroyDrawPlainString(proplist_t pl, void **func_data) {
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
drawPlainString (proplist_t pl, Drawable d,
|
||||
int x, int y, unsigned width, unsigned height,
|
||||
@@ -204,6 +210,8 @@ void initDrawFreeTypeString(proplist_t pl, void **init_data) {
|
||||
|
||||
data->glyphs_array = malloc(sizeof(WMFreeTypeRImage*) * MAX_GLYPHS);
|
||||
memset(data->glyphs_array, 0, sizeof(WMFreeTypeRImage*) * MAX_GLYPHS);
|
||||
data->glyphs_shadow_array = malloc(sizeof(WMFreeTypeRImage*) * MAX_GLYPHS);
|
||||
memset(data->glyphs_shadow_array, 0, sizeof(WMFreeTypeRImage*) * MAX_GLYPHS);
|
||||
|
||||
if (!rc) {
|
||||
RContextAttributes rcattr;
|
||||
@@ -217,7 +225,7 @@ void initDrawFreeTypeString(proplist_t pl, void **init_data) {
|
||||
|
||||
/* case 1 -- no no case 2 yet :P */
|
||||
if (!inst_ft_library) {
|
||||
FT_Init_FreeType(ft_library);
|
||||
FT_Init_FreeType(&ft_library);
|
||||
inst_ft_library++;
|
||||
}
|
||||
_debug("initialize freetype library\n");
|
||||
@@ -238,14 +246,58 @@ destroyDrawFreeTypeString(proplist_t pl, void **func_data) {
|
||||
RDestroyImage(data->glyphs_array[i]->image);
|
||||
free(data->glyphs_array[i]);
|
||||
}
|
||||
if (data->glyphs_shadow_array[i]) {
|
||||
if (data->glyphs_shadow_array[i]->image)
|
||||
RDestroyImage(data->glyphs_shadow_array[i]->image);
|
||||
free(data->glyphs_shadow_array[i]);
|
||||
}
|
||||
}
|
||||
free(data->glyphs_array);
|
||||
free(data);
|
||||
free(data->glyphs_shadow_array);
|
||||
FT_Done_Face(data->face);
|
||||
free(data);
|
||||
inst_ft_library--;
|
||||
if (!inst_ft_library) FT_Done_FreeType(ft_library);
|
||||
}
|
||||
|
||||
void
|
||||
logicalCombineArea(RImage *bg, RImage *image,
|
||||
int _sx, int _sy,
|
||||
int _sw, int _sh,
|
||||
int _dx, int _dy) {
|
||||
|
||||
if (_dx >= bg->width) {
|
||||
return;
|
||||
} else if (_dx + image->width > bg->width) {
|
||||
_sw = bg->width - _dx;
|
||||
}
|
||||
if (_dx + image->width < 0) {
|
||||
return;
|
||||
} else if (_dx < 0) {
|
||||
_sx = -_dx;
|
||||
_sw = image->width + _dx;
|
||||
_dx = 0;
|
||||
}
|
||||
|
||||
if (_dy >= bg->height) {
|
||||
return;
|
||||
} else if (_dy + image->height > bg->height) {
|
||||
_sh = bg->height - _dy;
|
||||
}
|
||||
if (_dy + image->height < 0) {
|
||||
return;
|
||||
} else if (_dy < 0) {
|
||||
_sy = -_dy;
|
||||
_sh = image->height + _dy;
|
||||
_dy = 0;
|
||||
}
|
||||
|
||||
if (_sh > 0 && _sw > 0)
|
||||
RCombineArea(bg, image, _sx, _sy,
|
||||
_sw, _sh, _dx, _dy);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
drawFreeTypeString (proplist_t pl, Drawable d,
|
||||
int x, int y, unsigned width, unsigned height,
|
||||
@@ -274,53 +326,22 @@ drawFreeTypeString (proplist_t pl, Drawable d,
|
||||
for (i = 0, j = 3; i < strlen(text); i++) {
|
||||
if (!data->glyphs_array[text[i]]) {
|
||||
data->glyphs_array[text[i]] = renderChar(data->face, (FT_ULong)text[i], &data->color);
|
||||
data->glyphs_shadow_array[text[i]] = renderChar(data->face, (FT_ULong)text[i], &black_color);
|
||||
_debug("alloc %c\n", text[i]);
|
||||
}
|
||||
if (data->glyphs_array[text[i]]->image) {
|
||||
int _sx, _dx, _sy, _dy, _sw, _sh;
|
||||
|
||||
_sx = 0;
|
||||
_sx = 0; _sy = 0;
|
||||
_dx = j + data->glyphs_array[text[i]]->left;
|
||||
_sw = data->glyphs_array[text[i]]->image->width;
|
||||
_sy = 0;
|
||||
_dy = rimg->height - data->glyphs_array[text[i]]->top ;
|
||||
_sw = data->glyphs_array[text[i]]->image->width;
|
||||
_sh = data->glyphs_array[text[i]]->image->height;
|
||||
|
||||
if (_dx >= rimg->width) {
|
||||
j += data->glyphs_array[text[i]]->advance_x >> 6;
|
||||
continue;
|
||||
} else if (_dx + data->glyphs_array[text[i]]->image->width > rimg->width) {
|
||||
_sw = rimg->width - _dx;
|
||||
}
|
||||
if (_dx + data->glyphs_array[text[i]]->image->width < 0) {
|
||||
j += data->glyphs_array[text[i]]->advance_x >> 6;
|
||||
continue;
|
||||
} else if (_dx < 0) {
|
||||
_sx = -_dx;
|
||||
_sw = data->glyphs_array[text[i]]->image->width + _dx;
|
||||
_dx = 0;
|
||||
}
|
||||
|
||||
|
||||
if (_dy >= rimg->height) {
|
||||
j += data->glyphs_array[text[i]]->advance_x >> 6;
|
||||
continue;
|
||||
} else if (_dy + data->glyphs_array[text[i]]->image->height > rimg->height) {
|
||||
_sh = rimg->height - _dy;
|
||||
}
|
||||
if (_dy + data->glyphs_array[text[i]]->image->height < 0) {
|
||||
j += data->glyphs_array[text[i]]->advance_x >> 6;
|
||||
continue;
|
||||
} else if (_dy < 0) {
|
||||
_sy = -_dy;
|
||||
_sh = data->glyphs_array[text[i]]->image->height + _dy;
|
||||
_dy = 0;
|
||||
}
|
||||
|
||||
|
||||
if (_sh > 0 && _sw > 0)
|
||||
RCombineArea(rimg, data->glyphs_array[text[i]]->image, _sx, _sy,
|
||||
_sw, _sh, _dx, _dy);
|
||||
logicalCombineArea(rimg, data->glyphs_shadow_array[text[i]]->image, _sx, _sy,
|
||||
_sw, _sh, _dx-2, _dy-2);
|
||||
logicalCombineArea(rimg, data->glyphs_array[text[i]]->image, _sx, _sy,
|
||||
_sw, _sh, _dx-3, _dy-3);
|
||||
|
||||
j += data->glyphs_array[text[i]]->advance_x >> 6;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user