Пример #1
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];
}
Пример #2
0
static IwinFont* winFindFont(const char *standardfont)
{
  HFONT hFont;
  int height_pixels;
  char typeface[50] = "";
  int height = 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];
  }

  /* parse the old format first */
  if (!iupFontParseWin(standardfont, typeface, &height, &is_bold, &is_italic, &is_underline, &is_strikeout))
  {
    if (!iupFontParsePango(standardfont, typeface, &height, &is_bold, &is_italic, &is_underline, &is_strikeout))
      return NULL;
  }

  mapped_name = iupFontGetWinName(typeface);
  if (mapped_name)
    strcpy(typeface, mapped_name);

  /* get in pixels */
  if (height < 0)  
    height_pixels = height;    /* already in pixels */
  else
    height_pixels = -IUPWIN_PT2PIXEL(height, 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,
                        typeface);
  if (!hFont)
    return NULL;

  /* create room in the array */
  fonts = (IwinFont*)iupArrayInc(win_fonts);

  strcpy(fonts[i].standardfont, standardfont);
  fonts[i].hFont = hFont;

  {
    TEXTMETRIC tm;
    HDC hdc = GetDC(NULL);
    HFONT oldfont = SelectObject(hdc, hFont);

    GetTextMetrics(hdc, &tm);

    SelectObject(hdc, oldfont);
    ReleaseDC(NULL, hdc);
    
    fonts[i].charwidth = tm.tmAveCharWidth; 
    fonts[i].charheight = tm.tmHeight;
  }

  return &fonts[i];
}