nanogui: drivers/genfont.c for HAVE_BIG5_SUPPORT


Previous by date: 17 Aug 2000 03:53:34 -0000 fonts/Makefile for HAVE_BIG5_SUPPORT, 曾昭明
Next by date: 17 Aug 2000 03:53:34 -0000 Re: config for HAVE_BIG5_SUPPORT, 曾昭明
Previous in thread:
Next in thread:

Subject: drivers/genfont.c for HAVE_BIG5_SUPPORT
From: ####@####.####
Date: 17 Aug 2000 03:53:34 -0000
Message-Id: <005801c007ff$595261c0$1b0448c0@gv.com.tw>

drivers/genfont.c for HAVE_BIG5_SUPPORT
/*
 * Generalized low level routine to calc bounding box for text output.
 * Handles both fixed and proportional fonts.  Passed ascii string.
 */
void
gen_gettextsize(PMWFONT pfont, const void *text, int cc,
 MWCOORD *pwidth, MWCOORD *pheight, MWCOORD *pbase)
{
 PMWCFONT  pf = ((PMWCOREFONT)pfont)->cfont;
 const unsigned char * str = text;
 unsigned int  c;
 int   width;

 if(pf->width == NULL)
  width = cc * pf->maxwidth;
 else {
  width = 0;
  while(--cc >= 0) {
   c = *str++;
+#if HAVE_BIG5_SUPPORT
+   /* chinese big5 decoding*/
+   if (c >= 0xA1 && c <= 0xF9 && cc >= 1 &&
+    ((*str >= 0x40 && *str <= 0x7E) ||
+     (*str >= 0xA1 && *str <= 0xFE)) ) {
+     --cc;
+     ++str;
+     width += 12; /* FIXME*/
+   } else
+#endif
#if HAVE_GB2312_SUPPORT
   /* chinese gb2312 decoding*/
   if (c >= 0xA1 && c < 0xF8 && cc >= 1 &&
    *str >= 0xA1 && *str < 0xFF) {
     --cc;
     ++str;
     width += 12; /* FIXME*/
   } else
#endif
       if(c >= pf->firstchar && c < pf->firstchar+pf->size)
                                width += pf->width[c - pf->firstchar];
  }
 }
 *pwidth = width;
 *pheight = pf->height;
 *pbase = pf->ascent;
}

/*
 * Generalized low level routine to get the bitmap associated
 * with a character.  Handles fixed and proportional fonts.
 */
void
gen_gettextbits(PMWFONT pfont, int ch, MWIMAGEBITS *retmap,
 MWCOORD *pwidth, MWCOORD *pheight, MWCOORD *pbase)
{
 PMWCFONT pf = ((PMWCOREFONT)pfont)->cfont;
 int   n, count, width;
 MWIMAGEBITS * bits;

+#if HAVE_BIG5_SUPPORT
+ /* decode chinese big5*/
+ int CH = ((unsigned int)ch) >> 8, CL = ((unsigned int)ch) & 0xFF;
+ if (CH >= 0xA1 && CH <= 0xF9 && ((CL >= 0x40 && CL <= 0x7E) || (CL >= 0xA1 && CL <= 0xFE)) ) 
+ {
+     int Pos;//!= ((CH - 0xA1) * 94 + (CL - 0xA1)) * 18;
+
+     int i;
+     extern unsigned char JMT_BIG5_12X12_FONT_BITMAP[];
+
+     int seq;
+     {
+  seq=0;
+  /* ladd=loby-(if(loby<127)?64:98)  */
+  CL/*c2*/-=(CL/*c2*/<127?64:98);   
+
+  /* hadd=(hiby-164)*157  */
+  if (CH/*c1*/>=0xa4)//standard font
+  {
+   seq=(((CH/*c1*/-164)*157)+CL/*c2*/);
+   if (seq>=5809) seq-=408;
+  }
+
+  /* hadd=(hiby-161)*157  */
+  if (CH/*c1*/<=0xa3)//special font
+   seq=(((CH/*c1*/-161)*157)+CL/*c2*/)+13094;
+     }
+     Pos=seq*18;
+
+     *pwidth = width = 12;
+     *pheight = 12;
+     *pbase = 0;
+
+     for (i = 0; i < 6; i++) {
+  unsigned char *DstBitmap  = ((unsigned char *)retmap) + i * 4;
+  unsigned char *FontBitmap = JMT_BIG5_12X12_FONT_BITMAP +
+   Pos + i * 3;
+  DstBitmap[0] = FontBitmap[1];
+  DstBitmap[1] = FontBitmap[0];
+  DstBitmap[2] = FontBitmap[1] << 4;
+  DstBitmap[3] = FontBitmap[2];
+     }
+     return;
+ }
+#endif /* HAVE_BIG5_SUPPORT*/

#if HAVE_GB2312_SUPPORT
 /* decode chinese gb2312*/
 int CH = ((unsigned int)ch) >> 8, CL = ((unsigned int)ch) & 0xFF;
 if (CH >= 0xA1 && CH < 0xF8 && CL >= 0xA1 && CL < 0xFF) {
     int Pos = ((CH - 0xA1) * 94 + (CL - 0xA1)) * 18;
     int i;
     extern unsigned char GUO_GB2312_12X12_FONT_BITMAP[];

     *pwidth = width = 12;
     *pheight = 12;
     *pbase = 0;

     for (i = 0; i < 6; i++) {
  unsigned char *DstBitmap  = ((unsigned char *)retmap) + i * 4;
  unsigned char *FontBitmap = GUO_GB2312_12X12_FONT_BITMAP +
   Pos + i * 3;
  DstBitmap[0] = FontBitmap[1];
  DstBitmap[1] = FontBitmap[0];
  DstBitmap[2] = FontBitmap[1] << 4;
  DstBitmap[3] = FontBitmap[2];
     }
     return;
 }
#endif /* HAVE_GB2312_SUPPORT*/

 /* if char not in font, map to first character by default*/
 if(ch < pf->firstchar || ch >= pf->firstchar+pf->size)
  ch = pf->firstchar;

 ch -= pf->firstchar;

 /* get font bitmap depending on fixed pitch or not*/
 bits = pf->bits + (pf->offset? pf->offset[ch]: (pf->height * ch));
 width = pf->width ? pf->width[ch] : pf->maxwidth;
 count = MWIMAGE_WORDS(width) * pf->height;
 for(n=0; n<count; ++n)
  *retmap++ = *bits++;

 /* return width depending on fixed pitch or not*/
 *pwidth = width;
 *pheight = pf->height;
 *pbase = pf->ascent;
}


[Content type application/x-zip-compressed not shown. Download]

Previous by date: 17 Aug 2000 03:53:34 -0000 fonts/Makefile for HAVE_BIG5_SUPPORT, 曾昭明
Next by date: 17 Aug 2000 03:53:34 -0000 Re: config for HAVE_BIG5_SUPPORT, 曾昭明
Previous in thread:
Next in thread:


Powered by ezmlm-browse 0.20.