static int iMatrixSetUndoClearAttrib(Ihandle* ih, const char* value) { ImatExData* matex_data = (ImatExData*)iupAttribGet(ih, "_IUP_MATEX_DATA"); int undo_stack_count = matex_data->undo_stack? iupArrayCount(matex_data->undo_stack): 0; if (undo_stack_count) { int i, undo_stack_count = iupArrayCount(matex_data->undo_stack); IundoData* undo_stack_data = (IundoData*)iupArrayGetData(matex_data->undo_stack); for (i=0; i<undo_stack_count; i++) iMatrixExUndoDataClear(&(undo_stack_data[i])); iupArrayRemove(matex_data->undo_stack, 0, undo_stack_count); matex_data->undo_stack_pos = 0; } (void)value; return 0; }
int iupTextSetAddFormatTagHandleAttrib(Ihandle* ih, const char* value) { Ihandle* formattag = (Ihandle*)value; if (!iupObjectCheck(formattag)) return 0; if (ih->handle) { /* must update VALUE before updating the format */ iTextUpdateValueAttrib(ih); iupdrvTextAddFormatTag(ih, formattag); IupDestroy(formattag); } else { Ihandle** tag_array; int i; if (!ih->data->formattags) ih->data->formattags = iupArrayCreate(10, sizeof(Ihandle*)); i = iupArrayCount(ih->data->formattags); tag_array = (Ihandle**)iupArrayInc(ih->data->formattags); tag_array[i] = formattag; } return 0; }
static void iMatrixUndoListUpdate(ImatExData* matex_data, Ihandle* ih_list) { int pos, item; char* undostr = IupGetLanguageString("IUP_UNDONAME"); char* redostr = IupGetLanguageString("IUP_REDONAME"); int undo_stack_count = iupArrayCount(matex_data->undo_stack); IundoData* undo_stack_data = (IundoData*)iupArrayGetData(matex_data->undo_stack); item = 1; for (pos=0; pos<matex_data->undo_stack_pos; pos++) { IupSetfAttributeId(ih_list, "", item, "%s: %s", undostr, undo_stack_data[pos].name); item++; } IupSetStrAttributeId(ih_list, "", item, "_@IUP_CURRENTSTATE"); item++; for (pos=matex_data->undo_stack_pos; pos<undo_stack_count; pos++) { IupSetfAttributeId(ih_list, "", item, "%s: %s", redostr, undo_stack_data[pos].name); item++; } IupSetAttributeId(ih_list, "", item, NULL); /* stack+current+null */ }
void iupTextUpdateFormatTags(Ihandle* ih) { /* called when the element is mapped */ int i, count = iupArrayCount(ih->data->formattags); Ihandle** tag_array = (Ihandle**)iupArrayGetData(ih->data->formattags); /* must update VALUE before updating the format */ iTextUpdateValueAttrib(ih); for (i = 0; i < count; i++) { char* bulk = iupAttribGet(tag_array[i], "BULK"); if (bulk && iupStrBoolean(bulk)) { Ihandle* child; void* state = iupdrvTextAddFormatTagStartBulk(ih); char* cleanout = iupAttribGet(tag_array[i], "CLEANOUT"); if (cleanout && iupStrBoolean(cleanout)) IupSetAttribute(ih, "REMOVEFORMATTING", "ALL"); for (child = tag_array[i]->firstchild; child; child = child->brother) iupdrvTextAddFormatTag(ih, child, 1); iupdrvTextAddFormatTagStopBulk(ih, state); } else iupdrvTextAddFormatTag(ih, tag_array[i], 0); IupDestroy(tag_array[i]); } iupArrayDestroy(ih->data->formattags); ih->data->formattags = NULL; }
static int iNormalizerSetNormalizeAttrib(Ihandle* ih, const char* value) { int i, count; Ihandle** ih_list; Ihandle* ih_control; int natural_maxwidth = 0, natural_maxheight = 0; int normalize = iNormalizeGetNormalizeSize(value); if (!normalize) return 1; count = iupArrayCount(ih->data->ih_array); ih_list = (Ihandle**)iupArrayGetData(ih->data->ih_array); for (i = 0; i < count; i++) { ih_control = ih_list[i]; iupClassObjectComputeNaturalSize(ih_control); natural_maxwidth = iupMAX(natural_maxwidth, ih_control->naturalwidth); natural_maxheight = iupMAX(natural_maxheight, ih_control->naturalheight); } for (i = 0; i < count; i++) { ih_control = ih_list[i]; if (!ih_control->floating && (ih_control->iclass->nativetype != IUP_TYPEVOID || !iupStrEqual(ih_control->iclass->name, "fill"))) { if (normalize & NORMALIZE_WIDTH) ih_control->userwidth = natural_maxwidth; if (normalize & NORMALIZE_HEIGHT) ih_control->userheight = natural_maxheight; } } return 1; }
static char* iMatrixGetUndoCountAttrib(Ihandle* ih) { ImatExData* matex_data = (ImatExData*)iupAttribGet(ih, "_IUP_MATEX_DATA"); int undo_stack_count = iupArrayCount(matex_data->undo_stack); if (matex_data->undo_stack && undo_stack_count) return iupStrReturnInt(undo_stack_count); return NULL; }
static void iMatrixExArrayAddStr(Iarray* data, char* str) { int add_count = strlen(str); int last_count = iupArrayCount(data); char* str_data = (char*)iupArrayAdd(data, add_count); memcpy(str_data+last_count, str, add_count); iMatrixExStrReplaceSep(str_data+last_count, add_count); }
static void gtkFileDlgGetMultipleFiles(Ihandle* ih, GSList* list) { int len, cur_len, dir_len = -1; char *filename, *all_names; Iarray* names_array = iupArrayCreate(1024, 1); /* just set an initial size, but count is 0 */ while (list) { filename = (char*)list->data; len = strlen(filename); if (dir_len == -1) { dir_len = len; while (dir_len && (filename[dir_len] != '/' && filename[dir_len] != '\\')) dir_len--; cur_len = iupArrayCount(names_array); all_names = iupArrayAdd(names_array, dir_len+1); memcpy(all_names+cur_len, filename, dir_len); all_names[cur_len+dir_len] = '0'; iupAttribStoreStr(ih, "DIRECTORY", all_names); all_names[cur_len+dir_len] = '|'; dir_len++; /* skip separator */ } len -= dir_len; /* remove directory */ cur_len = iupArrayCount(names_array); all_names = iupArrayAdd(names_array, len+1); memcpy(all_names+cur_len, filename+dir_len, len); all_names[cur_len+len] = '|'; g_free(filename); list = list->next; } cur_len = iupArrayCount(names_array); all_names = iupArrayInc(names_array); all_names[cur_len+1] = 0; iupAttribStoreStr(ih, "VALUE", iupgtkStrConvertFromFilename(all_names)); iupArrayDestroy(names_array); }
static char* iMatrixGetRedoAttrib(Ihandle* ih) { ImatExData* matex_data = (ImatExData*)iupAttribGet(ih, "_IUP_MATEX_DATA"); int undo_stack_count = matex_data->undo_stack? iupArrayCount(matex_data->undo_stack): 0; if (undo_stack_count) return iupStrReturnBoolean(matex_data->undo_stack_pos<undo_stack_count); return NULL; }
static int iNormalizerSetAddControlHandleAttrib(Ihandle* ih, const char* value) { Ihandle* ih_control = (Ihandle*)value; Ihandle** ih_list = (Ihandle**)iupArrayInc(ih->data->ih_array); int count = iupArrayCount(ih->data->ih_array); ih_list[count-1] = ih_control; return 0; }
static int motFileDlgGetMultipleFiles(Ihandle* ih, const char* dir, Widget wList) { int *pos, sel_count, dir_len; int i, len, cur_len; char *filename, *all_names; Iarray* names_array; XmString* items; if (!XmListGetSelectedPos(wList, &pos, &sel_count)) return 0; names_array = iupArrayCreate(1024, 1); /* just set an initial size, but count is 0 */ XtVaGetValues(wList, XmNitems, &items, NULL); cur_len = strlen(dir); all_names = iupArrayAdd(names_array, cur_len+1); memcpy(all_names, dir, cur_len); all_names[cur_len] = '|'; dir_len = cur_len; cur_len++; /* skip separator */ for (i = 0; i<sel_count; i++) { filename = iupmotConvertString(items[pos[i]-1]); /* XmListGetSelectedPos starts at 1 */ len = strlen(filename)-dir_len; cur_len = iupArrayCount(names_array); all_names = iupArrayAdd(names_array, len+1); memcpy(all_names+cur_len, filename+dir_len, len); all_names[cur_len+len] = '|'; } XtFree((char*)pos); cur_len = iupArrayCount(names_array); all_names = iupArrayInc(names_array); all_names[cur_len+1] = 0; iupAttribStoreStr(ih, "VALUE", all_names); iupArrayDestroy(names_array); return 1; }
static void iTextDestroyFormatTags(Ihandle* ih) { /* called if the element was destroyed before it was mapped */ int i, count = iupArrayCount(ih->data->formattags); Ihandle** tag_array = (Ihandle**)iupArrayGetData(ih->data->formattags); for (i = 0; i < count; i++) IupDestroy(tag_array[i]); iupArrayDestroy(ih->data->formattags); ih->data->formattags = NULL; }
void iupdrvFontFinish(void) { int i, count = iupArrayCount(win_fonts); IwinFont* fonts = (IwinFont*)iupArrayGetData(win_fonts); for (i = 0; i < count; i++) { DeleteObject(fonts[i].hFont); fonts[i].hFont = NULL; } iupArrayDestroy(win_fonts); }
static ImotFont* motFindFont(const char* foundry, const char *standardfont) { char xlfd[1024]; XFontStruct* fontstruct; int i, count = iupArrayCount(mot_fonts); int is_underline = 0, is_strikeout = 0; ImotFont* fonts = (ImotFont*)iupArrayGetData(mot_fonts); /* Check if the standardfont already exists in cache */ for (i = 0; i < count; i++) { if (iupStrEqualNoCase(standardfont, fonts[i].standardfont)) return &fonts[i]; } /* not found, create a new one */ if (standardfont[0] == '-') { fontstruct = XLoadQueryFont(iupmot_display, standardfont); if (!fontstruct) return NULL; strcpy(xlfd, standardfont); } else { int size, is_bold = 0, is_italic = 0; char typeface[1024]; const char* mapped_name; if (!iupFontParsePango(standardfont, typeface, &size, &is_bold, &is_italic, &is_underline, &is_strikeout)) return NULL; mapped_name = iupFontGetXName(typeface); if (mapped_name) strcpy(typeface, mapped_name); fontstruct = motLoadFont(foundry, typeface, size, is_bold, is_italic, xlfd); if (!fontstruct) return NULL; } /* create room in the array */ fonts = (ImotFont*)iupArrayInc(mot_fonts); strcpy(fonts[i].standardfont, standardfont); strcpy(fonts[i].xlfd, xlfd); fonts[i].fontstruct = fontstruct; fonts[i].fontlist = motFontCreateRenderTable(fontstruct, is_underline, is_strikeout); fonts[i].charwidth = motFontCalcCharWidth(fontstruct); fonts[i].charheight = fontstruct->ascent + fontstruct->descent; return &fonts[i]; }
void iupdrvFontFinish(void) { int i, count = iupArrayCount(gtk_fonts); IgtkFont* fonts = (IgtkFont*)iupArrayGetData(gtk_fonts); for (i = 0; i < count; i++) { pango_font_description_free(fonts[i].fontdesc); pango_attribute_destroy(fonts[i].strikethrough); pango_attribute_destroy(fonts[i].underline); } iupArrayDestroy(gtk_fonts); g_object_unref(gtk_fonts_context); }
void iupdrvFontFinish(void) { int i, count = iupArrayCount(mot_fonts); ImotFont* fonts = (ImotFont*)iupArrayGetData(mot_fonts); for (i = 0; i < count; i++) { XmFontListFree(fonts[i].fontlist); fonts[i].fontlist = NULL; XFreeFont(iupmot_display, fonts[i].fontstruct); fonts[i].fontstruct = NULL; } iupArrayDestroy(mot_fonts); }
static void iMatrixUndoStackAdd(ImatExData* matex_data, const char* name) { int i, undo_stack_count = iupArrayCount(matex_data->undo_stack); IundoData* undo_stack_data = (IundoData*)iupArrayGetData(matex_data->undo_stack); /* Remove all Redo data */ for (i=matex_data->undo_stack_pos; i<undo_stack_count; i++) iMatrixExUndoDataClear(&(undo_stack_data[i])); iupArrayRemove(matex_data->undo_stack, matex_data->undo_stack_pos, undo_stack_count-matex_data->undo_stack_pos); undo_stack_data = (IundoData*)iupArrayInc(matex_data->undo_stack); iMatrixExUndoDataInit(&(undo_stack_data[matex_data->undo_stack_pos]), name); }
char* iupwinFindHFont(HFONT hFont) { int i, count = iupArrayCount(win_fonts); /* Check if the standardfont already exists in cache */ IwinFont* fonts = (IwinFont*)iupArrayGetData(win_fonts); for (i = 0; i < count; i++) { if (hFont == fonts[i].hFont) return fonts[i].standardfont; } return NULL; }
char* iupgtkFindPangoFontDesc(PangoFontDescription* fontdesc) { int i, count = iupArrayCount(gtk_fonts); IgtkFont* fonts = (IgtkFont*)iupArrayGetData(gtk_fonts); /* Check if the standardfont already exists in cache */ for (i = 0; i < count; i++) { if (pango_font_description_equal(fontdesc, fonts[i].fontdesc)) return fonts[i].standardfont; } return NULL; }
static int iMatrixSetRedoAttrib(Ihandle* ih, const char* value) { ImatExData* matex_data = (ImatExData*)iupAttribGet(ih, "_IUP_MATEX_DATA"); int undo_stack_count = matex_data->undo_stack? iupArrayCount(matex_data->undo_stack): 0; if (undo_stack_count && matex_data->undo_stack_pos<undo_stack_count) { int i, count = 1, total_cell_count = 0, undo_stack_count = iupArrayCount(matex_data->undo_stack); IundoData* undo_stack_data = (IundoData*)iupArrayGetData(matex_data->undo_stack); iupStrToInt(value, &count); if (count > undo_stack_count - matex_data->undo_stack_pos) count = undo_stack_count - matex_data->undo_stack_pos; for (i=0; i<count; i++) total_cell_count += undo_stack_data[matex_data->undo_stack_pos + i].cell_count; iMatrixSetUndoRedoAttrib(ih, "NO"); /* Disable Undo/Redo systrem during restore */ iupMatrixExBusyStart(matex_data, total_cell_count, "REDO"); for (i=0; i<count; i++) { if (!iMatrixExUndoDataSwap(matex_data, &(undo_stack_data[matex_data->undo_stack_pos + i]))) { matex_data->undo_stack_pos += i; iMatrixSetUndoRedoAttrib(ih, "Yes"); return 0; } } iupMatrixExBusyEnd(matex_data); iMatrixSetUndoRedoAttrib(ih, "Yes"); matex_data->undo_stack_pos += i; iupBaseCallValueChangedCb(ih); } return 0; }
static char* iMatrixGetUndoNameAttrib(Ihandle* ih, int id) { ImatExData* matex_data = (ImatExData*)iupAttribGet(ih, "_IUP_MATEX_DATA"); int undo_stack_count = iupArrayCount(matex_data->undo_stack); if (matex_data->undo_stack && undo_stack_count) { IundoData* undo_stack_data = (IundoData*)iupArrayGetData(matex_data->undo_stack); if (id < 0 || id >= undo_stack_count) return NULL; return iupStrReturnStr(undo_stack_data[id].name); } return NULL; }
int iupTextSetAddFormatTagHandleAttrib(Ihandle* ih, const char* value) { Ihandle* formattag = (Ihandle*)value; if (!iupObjectCheck(formattag)) return 0; if (ih->handle) { char* bulk; /* must update VALUE before updating the format */ iTextUpdateValueAttrib(ih); bulk = iupAttribGet(formattag, "BULK"); if (bulk && iupStrBoolean(bulk)) { Ihandle* child; void* state = iupdrvTextAddFormatTagStartBulk(ih); char* cleanout = iupAttribGet(formattag, "CLEANOUT"); if (cleanout && iupStrBoolean(cleanout)) IupSetAttribute(ih, "REMOVEFORMATTING", "ALL"); for (child = formattag->firstchild; child; child = child->brother) iupdrvTextAddFormatTag(ih, child, 1); iupdrvTextAddFormatTagStopBulk(ih, state); } else iupdrvTextAddFormatTag(ih, formattag, 0); IupDestroy(formattag); } else { Ihandle** tag_array; int i; if (!ih->data->formattags) ih->data->formattags = iupArrayCreate(10, sizeof(Ihandle*)); i = iupArrayCount(ih->data->formattags); tag_array = (Ihandle**)iupArrayInc(ih->data->formattags); tag_array[i] = formattag; } return 0; }
void iupTextUpdateFormatTags(Ihandle* ih) { /* called when the element is mapped */ int i, count = iupArrayCount(ih->data->formattags); Ihandle** tag_array = (Ihandle**)iupArrayGetData(ih->data->formattags); /* must update VALUE before updating the format */ iTextUpdateValueAttrib(ih); for (i = 0; i < count; i++) { iupdrvTextAddFormatTag(ih, tag_array[i]); IupDestroy(tag_array[i]); } iupArrayDestroy(ih->data->formattags); ih->data->formattags = NULL; }
bool iupPlotDataReal::CalculateRange(double &outMin, double &outMax) const { int theCount = iupArrayCount(mArray); if (theCount > 0) { double* theData = (double*)iupArrayGetData(mArray); outMax = outMin = theData[0]; for (int i = 1; i < theCount; i++) { if (theData[i] > outMax) outMax = theData[i]; if (theData[i] < outMin) outMin = theData[i]; } return true; } return false; }
static int iMatrixExSetCopyAttrib(Ihandle *ih, const char* value) { ImatExData* matex_data = (ImatExData*)iupAttribGet(ih, "_IUP_MATEX_DATA"); Iarray* data = iupArrayCreate(100, sizeof(char)); iMatrixExCopyData(matex_data, data, value); if (iupArrayCount(data)!=0) { Ihandle* clipboard; iMatrixExArrayAddChar(data, '\0'); clipboard = IupClipboard(); IupSetAttribute(clipboard, "TEXT", NULL); /* clear all data from clipboard */ IupSetAttribute(clipboard, "TEXT", (char*)iupArrayGetData(data)); IupDestroy(clipboard); } iupArrayDestroy(data); return 0; }
static int iMatrixExSetCopyDataAttrib(Ihandle *ih, const char* value) { if (!value) iupAttribSet(ih, "COPYDATA", NULL); else { ImatExData* matex_data = (ImatExData*)iupAttribGet(ih, "_IUP_MATEX_DATA"); Iarray* data = iupArrayCreate(100, sizeof(char)); iMatrixExCopyData(matex_data, data, value); if (iupArrayCount(data)!=0) { iMatrixExArrayAddChar(data, '\0'); iupAttribSetStr(ih, "COPYDATA", (char*)iupArrayGetData(data)); } iupArrayDestroy(data); } return 0; }
static IwinFont* winFindFont(const char *standardfont) { HFONT hFont; int height_pixels; /* negative value */ char typeface[50] = ""; int size = 8; int is_bold = 0, is_italic = 0, is_underline = 0, is_strikeout = 0; int res = iupwinGetScreenRes(); int i, count = iupArrayCount(win_fonts); const char* mapped_name; /* Check if the standardfont already exists in cache */ IwinFont* fonts = (IwinFont*)iupArrayGetData(win_fonts); for (i = 0; i < count; i++) { if (iupStrEqualNoCase(standardfont, fonts[i].standardfont)) return &fonts[i]; } if (!iupGetFontInfo(standardfont, typeface, &size, &is_bold, &is_italic, &is_underline, &is_strikeout)) return NULL; /* Map standard names to native names */ mapped_name = iupFontGetWinName(typeface); if (mapped_name) strcpy(typeface, mapped_name); /* get in pixels */ if (size < 0) height_pixels = size; /* already in pixels */ else height_pixels = -iupWIN_PT2PIXEL(size, res); if (height_pixels == 0) return NULL; hFont = CreateFont(height_pixels, 0,0,0, (is_bold) ? FW_BOLD : FW_NORMAL, is_italic, is_underline, is_strikeout, DEFAULT_CHARSET,OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY, FF_DONTCARE|DEFAULT_PITCH, iupwinStrToSystem(typeface)); if (!hFont) return NULL; /* create room in the array */ fonts = (IwinFont*)iupArrayInc(win_fonts); strcpy(fonts[i].standardfont, standardfont); fonts[i].hFont = hFont; { HDC hdc = GetDC(NULL); HFONT oldfont = (HFONT)SelectObject(hdc, hFont); TEXTMETRIC tm; GetTextMetrics(hdc, &tm); /* NOTICE that this is different from CD. In IUP we need "average" width, in CD is "maximum" width. */ fonts[i].charwidth = tm.tmAveCharWidth; fonts[i].charheight = tm.tmHeight; SelectObject(hdc, oldfont); ReleaseDC(NULL, hdc); } return &fonts[i]; }
static void iMatrixExArrayAddChar(Iarray* data, char c) { int last_count = iupArrayCount(data); char* str_data = (char*)iupArrayInc(data); str_data[last_count] = c; }
static IgtkFont* gtkFindFont(const char *standardfont) { PangoFontMetrics* metrics; PangoFontDescription* fontdesc; int i, is_underline = 0, is_strikeout = 0, count = iupArrayCount(gtk_fonts); IgtkFont* fonts = (IgtkFont*)iupArrayGetData(gtk_fonts); /* Check if the standardfont already exists in cache */ for (i = 0; i < count; i++) { if (iupStrEqualNoCase(standardfont, fonts[i].standardfont)) return &fonts[i]; } /* not found, create a new one */ { int size; int is_bold = 0, is_italic = 0; char typeface[1024]; char *new_standardfont = NULL; const char* mapped_name; if (!iupFontParsePango(standardfont, typeface, &size, &is_bold, &is_italic, &is_underline, &is_strikeout)) return NULL; mapped_name = iupFontGetPangoName(typeface); if (mapped_name) strcpy(typeface, mapped_name); if (is_underline || is_strikeout || size<0) new_standardfont = iupStrDup(standardfont); if (is_underline) { char* under = strstr(standardfont, "Underline"); int len = strlen(standardfont); int len1 = (size_t)(under-standardfont); memcpy(new_standardfont, standardfont, len1); memcpy(new_standardfont+len1, under+9+1, len-len1-9+1); /* strlen("Underline") */ standardfont = new_standardfont; } if (is_strikeout) { char* strike = strstr(standardfont, "Strikeout"); int len = strlen(standardfont); int len1 = (size_t)(strike-standardfont); memcpy(new_standardfont, standardfont, len1); memcpy(new_standardfont+len1, strike+9+1, len-len1-9+1); /* strlen("Strikeout") */ standardfont = new_standardfont; } if (size<0) { double res; int len1, len2; char *sz, size_str[10]; sprintf(size_str, "%d", size); sz = strstr(standardfont, size_str); len1 = (size_t)(sz-standardfont); res = ((double)gdk_screen_get_width(gdk_screen_get_default()) / (double)gdk_screen_get_width_mm(gdk_screen_get_default())); /* pixels/mm */ /* 1 point = 1/72 inch 1 inch = 25.4 mm */ /* pixel = ((point/72)*25.4)*pixel/mm */ size = (int)((-size/res)*2.83464567 + 0.5); /* from pixels to points */ len2 = sprintf(size_str, "%d", size); memcpy(new_standardfont, standardfont, len1); memcpy(new_standardfont+len1, size_str, len2+1); } fontdesc = pango_font_description_from_string(standardfont); if (new_standardfont) free(new_standardfont); } if (!fontdesc) return NULL; /* create room in the array */ fonts = (IgtkFont*)iupArrayInc(gtk_fonts); strcpy(fonts[i].standardfont, standardfont); fonts[i].fontdesc = fontdesc; fonts[i].strikethrough = pango_attr_strikethrough_new(is_strikeout? TRUE: FALSE); fonts[i].underline = pango_attr_underline_new(is_underline? PANGO_UNDERLINE_SINGLE: PANGO_UNDERLINE_NONE); fonts[i].layout = pango_layout_new(gtk_fonts_context); metrics = pango_context_get_metrics(gtk_fonts_context, fontdesc, pango_context_get_language(gtk_fonts_context)); fonts[i].charheight = pango_font_metrics_get_ascent(metrics) + pango_font_metrics_get_descent(metrics); fonts[i].charheight = IUPGTK_PANGOUNITS2PIXELS(fonts[i].charheight); fonts[i].charwidth = pango_font_metrics_get_approximate_char_width(metrics); fonts[i].charwidth = IUPGTK_PANGOUNITS2PIXELS(fonts[i].charwidth); pango_font_metrics_unref(metrics); gtkFontUpdate(&(fonts[i])); return &fonts[i]; }
static IgtkFont* gtkFindFont(const char *standardfont) { PangoFontMetrics* metrics; PangoFontDescription* fontdesc; int i, is_underline = 0, is_strikeout = 0, count = iupArrayCount(gtk_fonts); IgtkFont* fonts = (IgtkFont*)iupArrayGetData(gtk_fonts); /* Check if the standardfont already exists in cache */ for (i = 0; i < count; i++) { if (iupStrEqualNoCase(standardfont, fonts[i].standardfont)) return &fonts[i]; } /* not found, create a new one */ { int size = 0, is_pango = 0; int is_bold = 0, is_italic = 0; char typeface[1024]; const char* mapped_name; /* parse the old Windows format first */ if (!iupFontParseWin(standardfont, typeface, &size, &is_bold, &is_italic, &is_underline, &is_strikeout)) { if (!iupFontParseX(standardfont, typeface, &size, &is_bold, &is_italic, &is_underline, &is_strikeout)) { if (!iupFontParsePango(standardfont, typeface, &size, &is_bold, &is_italic, &is_underline, &is_strikeout)) return NULL; else is_pango = 1; } } mapped_name = iupFontGetPangoName(typeface); if (mapped_name) strcpy(typeface, mapped_name); if (is_pango && !is_underline && !is_strikeout && size>0) fontdesc = pango_font_description_from_string(standardfont); else { char new_standardfont[200]; if (size<0) { double res = ((double)gdk_screen_get_width(gdk_screen_get_default()) / (double)gdk_screen_get_width_mm(gdk_screen_get_default())); /* pixels/mm */ /* 1 point = 1/72 inch 1 inch = 25.4 mm */ /* pixel = ((point/72)*25.4)*pixel/mm */ size = (int)((-size/res)*2.83464567 + 0.5); /* from pixels to points */ } sprintf(new_standardfont, "%s, %s%s%d", typeface, is_bold?"Bold ":"", is_italic?"Italic ":"", size); fontdesc = pango_font_description_from_string(new_standardfont); } } if (!fontdesc) return NULL; /* create room in the array */ fonts = (IgtkFont*)iupArrayInc(gtk_fonts); strcpy(fonts[i].standardfont, standardfont); fonts[i].fontdesc = fontdesc; fonts[i].strikethrough = pango_attr_strikethrough_new(is_strikeout? TRUE: FALSE); fonts[i].underline = pango_attr_underline_new(is_underline? PANGO_UNDERLINE_SINGLE: PANGO_UNDERLINE_NONE); fonts[i].layout = pango_layout_new(gtk_fonts_context); metrics = pango_context_get_metrics(gtk_fonts_context, fontdesc, pango_context_get_language(gtk_fonts_context)); fonts[i].charheight = pango_font_metrics_get_ascent(metrics) + pango_font_metrics_get_descent(metrics); fonts[i].charheight = IUPGTK_PANGOUNITS2PIXELS(fonts[i].charheight); fonts[i].charwidth = pango_font_metrics_get_approximate_char_width(metrics); fonts[i].charwidth = IUPGTK_PANGOUNITS2PIXELS(fonts[i].charwidth); pango_font_metrics_unref(metrics); gtkFontUpdate(&(fonts[i])); return &fonts[i]; }