Text * new_text(const char *string, Font *font, real height, Point *pos, Color *color, Alignment align) { Text *text; text = g_new(Text, 1); text->font = font; text->height = height; text->position = *pos; text->color = *color; text->alignment = align; text->cursor_pos = 0; text->cursor_row = 0; text->focus.obj = NULL; text->focus.has_focus = FALSE; text->focus.user_data = (void *)text; text->focus.key_event = text_key_event; set_string(text, string); calc_width(text); calc_ascent_descent(text); return text; }
void text_set_font(Text *text, Font *font) { text->font = font; calc_width(text); calc_ascent_descent(text); }
void text_set_height(Text *text, real height) { text->height = height; calc_width(text); calc_ascent_descent(text); }
void text_set_height(Text *text, real height) { int i; text->height = height; for (i = 0; i < text->numlines; i++) { text_line_set_height(text->lines[i], height); } calc_width(text); calc_ascent_descent(text); }
int text_delete_all(Text *text, ObjectChange **change, DiaObject *obj) { if (!text_is_empty(text)) { *change = text_create_change(text, TYPE_DELETE_ALL, 0, text->cursor_pos, text->cursor_row, obj); text_set_string(text, ""); calc_ascent_descent(text); return TRUE; } return FALSE; }
void text_set_font(Text *text, DiaFont *font) { DiaFont *old_font = text->font; int i; text->font = dia_font_ref(font); dia_font_unref(old_font); for (i = 0; i < text->numlines; i++) { text_line_set_font(text->lines[i], font); } calc_width(text); calc_ascent_descent(text); }
void text_calc_boundingbox(Text *text, Rectangle *box) { calc_width(text); calc_ascent_descent(text); if (box == NULL) return; /* For those who just want the text info updated */ box->left = text->position.x; switch (text->alignment) { case ALIGN_LEFT: break; case ALIGN_CENTER: box->left -= text->max_width / 2.0; break; case ALIGN_RIGHT: box->left -= text->max_width; break; } box->right = box->left + text->max_width; box->top = text->position.y - text->ascent; #if 0 box->bottom = box->top + text->height*text->numlines + text->descent; #else /* why should we add one descent? isn't ascent+descent~=height? */ box->bottom = box->top + (text->ascent+text->descent+text->height*(text->numlines-1)); #endif if (text->focus.has_focus) { real height = text->ascent + text->descent; if (text->cursor_pos == 0) { /* Half the cursor width */ box->left -= height/(CURSOR_HEIGHT_RATIO*2); } else { /* Half the cursor width. Assume that if it isn't at position zero, it might be at the last position possible. */ box->right += height/(CURSOR_HEIGHT_RATIO*2); } /* Account for the size of the cursor top and bottom */ box->top -= height/(CURSOR_HEIGHT_RATIO*2); box->bottom += height/CURSOR_HEIGHT_RATIO; } }