Loading ...
Sorry, an error occurred while loading the content.

problem with font width

Expand Messages
  • Shugo Maeda
    Hi, If the width of the font for multi-byte characters is not twice as much as the width of the font for single-byte characters, the window gets broken on the
    Message 1 of 2 , Sep 21, 2000
    • 0 Attachment
      Hi,

      If the width of the font for multi-byte characters is not twice
      as much as the width of the font for single-byte characters, the
      window gets broken on the cursor move.

      I made a quick-hack patch for gui_gtk_x11.c (version 6.0h).
      I think It's not complete but useful.

      Shugo

      --- gui_gtk_x11.c.orig Fri Sep 22 02:44:42 2000
      +++ gui_gtk_x11.c Fri Sep 22 14:08:23 2000
      @@ -2649,6 +2649,30 @@
      gui.bgcolor->pixel = (Pixel) color;
      }

      +#ifdef FEAT_MBYTE
      + void
      +draw_mb_text(GdkDrawable *drawable,
      + GdkFont *font,
      + GdkGC *gc,
      + gint x,
      + gint y,
      + char_u *text,
      + int textlen)
      +{
      + int len;
      +
      + while (textlen > 0)
      + {
      + len = mb_ptr2len_check(text);
      + gdk_draw_text(drawable, font, gc,
      + x, y, (const gchar *) text, len);
      + x += (len * gui.char_width);
      + text += len;
      + textlen -= len;
      + }
      +}
      +#endif
      +
      void
      gui_mch_draw_string(int row, int col, char_u *s, int len, int flags)
      {
      @@ -2728,18 +2752,32 @@
      if (flags & DRAW_TRANSP)
      {
      gdk_gc_set_foreground(gui.text_gc, gui.fgcolor);
      - gdk_draw_text(gui.drawarea->window,
      - gui.current_font,
      - gui.text_gc,
      - TEXT_X(col), TEXT_Y(row),
      - (const gchar *)text, textlen);
      +#ifdef FEAT_MBYTE
      + if (cc_dbcs && !is_wide)
      + draw_mb_text(gui.drawarea->window,
      + gui.current_font,
      + gui.text_gc,
      + TEXT_X(col), TEXT_Y(row),
      + (char_u *)text, textlen);
      + else
      +#endif
      + gdk_draw_text(gui.drawarea->window,
      + gui.current_font,
      + gui.text_gc,
      + TEXT_X(col), TEXT_Y(row),
      + (const gchar *)text, textlen);
      }
      else
      {
      int width;
      int height;

      - width = gdk_text_width(gui.current_font, (const gchar *)text, textlen);
      +#ifdef FEAT_MBYTE
      + if (cc_dbcs && !is_wide)
      + width = textlen * gui.char_width;
      + else
      +#endif
      + width = gdk_text_width(gui.current_font, (const gchar *)text, textlen);
      height = gui.char_height;

      gdk_gc_set_foreground(gui.text_gc, gui.bgcolor);
      @@ -2748,21 +2786,39 @@
      TRUE,
      FILL_X(col), FILL_Y(row), width, height);
      gdk_gc_set_foreground(gui.text_gc, gui.fgcolor);
      - gdk_draw_text(gui.drawarea->window,
      - gui.current_font,
      - gui.text_gc,
      - TEXT_X(col), TEXT_Y(row),
      - (const gchar *)text, textlen);
      +#ifdef FEAT_MBYTE
      + if (cc_dbcs && !is_wide)
      + draw_mb_text(gui.drawarea->window,
      + gui.current_font,
      + gui.text_gc,
      + TEXT_X(col), TEXT_Y(row),
      + (char_u *)text, textlen);
      + else
      +#endif
      + gdk_draw_text(gui.drawarea->window,
      + gui.current_font,
      + gui.text_gc,
      + TEXT_X(col), TEXT_Y(row),
      + (const gchar *)text, textlen);
      }

      /* redraw the contents with an offset of 1 to emulate bold */
      if (flags & DRAW_BOLD)
      {
      - gdk_draw_text(gui.drawarea->window,
      - gui.current_font,
      - gui.text_gc,
      - TEXT_X(col) + 1, TEXT_Y(row),
      - (const gchar *)text, textlen);
      +#ifdef FEAT_MBYTE
      + if (cc_dbcs && !is_wide)
      + draw_mb_text(gui.drawarea->window,
      + gui.current_font,
      + gui.text_gc,
      + TEXT_X(col) + 1, TEXT_Y(row),
      + (char_u *)text, textlen);
      + else
      +#endif
      + gdk_draw_text(gui.drawarea->window,
      + gui.current_font,
      + gui.text_gc,
      + TEXT_X(col) + 1, TEXT_Y(row),
      + (const gchar *)text, textlen);
      }

      if (flags & DRAW_UNDERL)
    • Bram Moolenaar
      ... Well, the proper fix is to get a font that s really double-width. ... This looks like a patch that goes into the direction of supporting proportional
      Message 2 of 2 , Sep 30, 2000
      • 0 Attachment
        Shugo Maeda wrote:

        > If the width of the font for multi-byte characters is not twice
        > as much as the width of the font for single-byte characters, the
        > window gets broken on the cursor move.

        Well, the proper fix is to get a font that's really double-width.

        > I made a quick-hack patch for gui_gtk_x11.c (version 6.0h).
        > I think It's not complete but useful.

        This looks like a patch that goes into the direction of supporting
        proportional fonts. It draws each character separately. However, I suspect
        the background isn't always redrawn correctly. Also, the same should be done
        for other GUI verions. I rather wait for a better patch.

        --
        hundred-and-one symptoms of being an internet addict:
        87. Everyone you know asks why your phone line is always busy ...and
        you tell them to send an e-mail.

        /// Bram Moolenaar Bram@... http://www.moolenaar.net \\\
        \\\ Vim: http://www.vim.org ICCF Holland: http://iccf-holland.org ///
      Your message has been successfully submitted and would be delivered to recipients shortly.