discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: 2-bytes character display ready ?


From: Yen-Ju Chen
Subject: RE: 2-bytes character display ready ?
Date: Tue, 19 Feb 2002 18:19:31 -0500

  After another try, I found I can show 2bytes character (Chinese) by only
modified XGFont.m

  This is the way I did.
  1. Add a XFontSet in XGFontInfo declaration in XGContextPrivate.h file.
  2. Initiate the XFontSet in  -initWithFontName of XGFont.m
  3. In - drawString: and - draw: of XGFont.m,
      use XmbDrawString instead XDrawString.
      XmbDrawString need XFontSet to display correctly.

  That's all. I don't need to modify any source code in gui and DPSxxx()
anymore.
  So the question is: How do I know the encoding of a string (char*) ?

  I test NSTextField and NSButton,
  and only -draw: in XGFont.m is used for NSTextField and NSButton.
  But -draw: use char*, not NSString.
  Therefore, I can't tell which encoding it is.

  The reason that most i18n softwares use XmbDrawString instead
XDrawString16
  is because people always mix 1bytes and 2bytes character in their
language.
  When they input 2bytes character (native language),
  the software need use 2bytes font.
  When they input english, western language or number,
  the software need use 1bytes font (because 2byte font is ugly for 1byes
character).
  I think that's the reason they use XFontSet to solve the problem of
switching fonts.
  But as Fred said, XFontSet doesn't give a rang of information.

  Maybe Xft will support 2bytes character better then Xlib.
  I will try to use Xft later.
  When I use Xft in backend (anti-alias), the Ink.app can find all Chinese
fonts,
  but XGFont fails to find Chinese fonts.

  The reason I would like to add 2bytes support in either XGFont or
XftFontInfo
  is that as I said above, people always use 1bytes and 2bytes at the same
time,
  depending what kind of  character they type.
  Make another XGFont support is not a usual way I know.

  Thanx for all the discussion.
  Thats help a lot.

  Below is the source code I modified.

  Yen-Ju

In XGContextPrivate.h

@interface XGFontInfo: GSFontInfo
{
  XFontStruct *font_info;
  XFontSet fontset; <=== I add this one
}

In XGFont.m

- initWithFontName: (NSString *)name .....
{
  char **missing_charset_list_return;
  int missing_charset_count_return;
  char *def_string_return;
  NSString *basename2;
  Display *xdpy = [XGContext currentDisplay];

  -- skip --

  basename2 = [name stringByAppendingString: @",*"];
  if ((fontset = XCreateFontSet(xdpy, [basename2 cString],

&missing_charset_list_return,

&missing_charset_count_return,

&def_string_return )) = NULL)
  {
    NSLog(@"Fail to initiate XFontSet");
  }

  return self
}

- (void) drawString: (NSString *)string ...
{
  --skip--

  XmbDrawString(xdpy, draw, fontset, xgcntxt, xp.x, xp.y, cstr, length);
// XDrawString(xdpy, draw, xgcntxt, xp.x, xp.y, cstr, length);
}

- (void) draw: (const char*) s ...
{
    XmbDrawString(xdpy, draw, fontset, xgcntxt, xp.x, xp.y, s, len);
// XDrawString(xdpy, draw, xgcntxt, xp.x, xp.y, s, len);
}

> -----Original Message-----
> From: Fred Kiefer [mailto:fredkiefer@gmx.de]
> Sent: Tuesday, February 19, 2002 3:23 PM
> To: Yen-Ju Chen; discuss-gnustep@gnu.org
> Subject: Re: 2-bytes character display ready ?
>
>
> This sounds great!
>
> Yen-Ju Chen wrote:
>
>  > I try some modification and start getting some good results. :) This
>  >  is what I did:
>  >
>  > 1. In NSStringDrawing, use encode_unitochar_strict instead
> encode_unitochar.
>  >
>
>  > 2. Change char to unsigned char in DPSshow.
>
>
> You surely refer to "unsigned" as meaning "unsigned in" not "unsigned
> char" here. Otherwise this would not make much difference.
>
>  > 3. In XGFont.m, use XFontSet to set the Font.
> This last step should not be needed. There is an X interface to draw 16
> bit strings. As far as I remember I put a comment on this in the code.
> Still font sets are fun to have, the only problem being that you don't
> get that range of informations on them, as you get for normal strings.
> What I would suggest is that you make just another subclass of
> GSFontInfo and register that in initializeBackend, as I did for
> XftFontInfo to gat simple anti-aliasing.
>
>
>  > Then I can show 2-bytes character in NSTextField and NSButton !! That
>  >  is a ugly modification because I'm not familiar with Xlib and unicode.
>  >
>
>  >
>  > Is the PostScript interface means char vs unsigned char ? I found
>  > DPSxxx() always accept const char.
>  >
>  > Since ASCII character is a subset of 2bytes character, I hope
>  > GNUstep can include the ability to handle 2bytes character. I have
>  > no idea how hard it will be, or how it will break the PostScript
>  > interface. But here is my idea after my first successful try, which
>  >  may totally wrong. 1. Add XFontSet into GSFontInfo interface. XFontSet
>  >  can handle the font for 2bytes character. 2. Initiate XFontSet as
>  > XFontStruct in XGFont.m. That's the most difficult part for me. Too
>  >  many parameters. 3. If it won't break any interface, use unsigned
>  > char instead char.
>  >
> This is exactly the change I was refering to in my mail. But now that
> you can proof that this extension would be needed, some people might
> change their mind and we might get this additional interface.
>
> Cheers
> Fred
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]