Ticket #384: font_hdc.patch

File font_hdc.patch, 4.0 kB (added by yamazaki, 10 months ago)

hdcを使いまわすパッチ

  • mw32font.c

    old new  
    7373 
    7474int mw32_lf_loader_num = 0; 
    7575LOADLFPROC mw32_lf_loaders[10]; 
     76static HDC mw32_font_hdc = NULL; 
    7677 
    7778static Lisp_Object mw32_get_font_request_parameter (Lisp_Object, Lisp_Object); 
    7879 
     
    189190 
    190191  { 
    191192    HANDLE hold; 
    192     HDC hdc = GetDC (NULL); 
    193193 
     194    if (!mw32_font_hdc) 
     195      mw32_font_hdc = CreateIC ("DISPLAY", NULL, NULL, NULL); 
     196 
    194197    if (pwf->pfont == INVALID_HANDLE_VALUE) 
    195198      pwf->pfont = CreateFontIndirect (&pwf->logfont); 
    196     hold = SelectObject (hdc, pwf->pfont); 
     199    hold = SelectObject (mw32_font_hdc, pwf->pfont); 
    197200 
    198201    if (pwf->ttfp) 
    199202      { 
    200203        ABC abc; 
    201         int ret = GetCharABCWidths (hdc, *cp, *cp, &abc); 
     204        int ret = GetCharABCWidths (mw32_font_hdc, *cp, *cp, &abc); 
    202205 
    203206        if (ret) 
    204207          { 
     
    208211          } 
    209212        else 
    210213          { 
    211             SelectObject (hdc, hold); 
    212             ReleaseDC (NULL, hdc); 
     214            SelectObject (mw32_font_hdc, hold); 
    213215            return 0; 
    214216          } 
    215217      } 
     
    221223 
    222224        p = str; 
    223225        SERIALIZE_FONTCP (p, *cp); 
    224         if (GetTextExtentPoint32 (hdc, str, p - str, &sz)) 
     226        if (GetTextExtentPoint32 (mw32_font_hdc, str, p - str, &sz)) 
    225227          { 
    226228            pwf->cur_cm.width = sz.cx; 
    227229          } 
    228230        else 
    229231          { 
    230232            int w; 
    231             GetCharWidth (hdc, *cp, *cp, &w); 
     233            GetCharWidth (mw32_font_hdc, *cp, *cp, &w); 
    232234            pwf->cur_cm.width = w; 
    233235          } 
    234236        pwf->cur_cm.rbearing = pwf->cur_cm.width; 
     
    238240      } 
    239241    pwf->cur_cm.ascent = plf->ascent; 
    240242    pwf->cur_cm.descent = plf->descent; 
    241     pwf->cur_cm.width += get_device_width (hdc, plf->character_spacing); 
     243    pwf->cur_cm.width += get_device_width (mw32_font_hdc, plf->character_spacing); 
    242244 
    243     SelectObject (hdc, hold); 
    244     ReleaseDC (NULL, hdc); 
     245    SelectObject (mw32_font_hdc, hold); 
    245246  } 
    246247  if (plf->encoding.font_unit_byte == 1) 
    247248    pwf->cmcache[*cp] = pwf->cur_cm; 
     
    357358  /* set attributes. */ 
    358359  if (hf = CreateFontIndirect (plogf)) 
    359360    { 
    360       HWND hwnd; 
    361361      HDC hdc; 
    362362      HANDLE oldobj; 
    363363      TEXTMETRIC tm; 
     
    512512      cm.rbearing = 0; 
    513513    } 
    514514  { 
    515     HDC hdc = GetDC (NULL); 
    516     cm.width += get_device_width (hdc, plf->character_spacing); 
    517     ReleaseDC (NULL, hdc); 
     515    if (!mw32_font_hdc) 
     516      mw32_font_hdc = CreateIC ("DISPLAY", NULL, NULL, NULL); 
     517 
     518    cm.width += get_device_width (mw32_font_hdc, plf->character_spacing); 
    518519  } 
    519520 
    520521  return &cm; 
     
    28122813  return result; 
    28132814} 
    28142815 
     2816/* clean up */ 
     2817void 
     2818mw32_font_cleanup (void) 
     2819{ 
     2820  if (mw32_font_hdc) 
     2821    DeleteDC (mw32_font_hdc); 
     2822} 
     2823 
    28152824/* syms */ 
    28162825syms_of_mw32font () 
    28172826{ 
  • mw32font.h

    old new  
    196196                                          struct face *face, int c)); 
    197197extern void mw32_delete_logical_font P_ ((MW32LogicalFont *plf)); 
    198198extern void mw32_initialize_default_logfont P_ ((LOGFONT*)); 
     199extern void mw32_font_cleanup P_ ((void)); 
    199200 
    200201#endif  /* __MW32_FONT__ */ 
  • w32.c

    old new  
    8282#include "coding.h" 
    8383#include "mw32reg.h" 
    8484#include "mw32sync.h" 
     85#include "mw32font.h" 
    8586 
    8687extern Lisp_Object Vfile_name_coding_system; 
    8788#endif 
     
    45004501  term_winsock (); 
    45014502#endif 
    45024503 
     4504#ifdef MEADOW 
     4505  mw32_font_cleanup (); 
     4506#endif 
     4507 
    45034508#ifndef MEADOW 
    45044509  term_w32select (); 
    45054510#endif 
  • dispnew.c

    old new  
    39003900  int paused_p; 
    39013901  struct window *root_window = XWINDOW (f->root_window); 
    39023902 
    3903 #ifdef MEADOW 
    3904   GET_FRAME_HDC (f); 
    3905 #endif 
    39063903  if (redisplay_dont_pause) 
    39073904    force_p = 1; 
    39083905#if PERIODIC_PREEMPTION_CHECKING 
     
    40064003      add_frame_display_history (f, paused_p); 
    40074004#endif 
    40084005    } 
    4009 #ifdef MEADOW 
    4010   RELEASE_FRAME_HDC (f); 
    4011 #endif 
    40124006 
    40134007 do_pause: 
    40144008  /* Reset flags indicating that a window should be updated.  */