⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basic-x.c

📁 Pango is a library for layout and rendering of text, with an emphasis on internationalization. Pang
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Pango * basic.c: * * Copyright (C) 1999 Red Hat Software * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */#include <config.h>#include <glib.h>#include <string.h>#include "pango-engine.h"#include "pango-utils.h"#undef PANGO_DISABLE_DEPRECATED#include "pangox.h"/* No extra fields needed */typedef PangoEngineShape      BasicEngineX;typedef PangoEngineShapeClass BasicEngineXClass ;typedef struct _CharRange CharRange;typedef struct _Charset Charset;typedef struct _CharsetOrdering CharsetOrdering;typedef struct _CharCache CharCache;typedef struct _CharCachePointer CharCachePointer;typedef struct _MaskTable MaskTable;typedef PangoGlyph (*ConvFunc) (CharCache   *cache,				GIConv       cd,				const gchar *input);#define MAX_CHARSETS 32#define SCRIPT_ENGINE_NAME "BasicScriptEngineX"struct _Charset{  int   index;  const char *id;  const char *x_charset;  ConvFunc conv_func;};struct _CharsetOrdering{  const char *langs;  char charsets[MAX_CHARSETS];};struct _CharRange{  guint16 start;  guint16 end;  guint16 charsets;};struct _MaskTable{  int n_subfonts;  PangoXSubfont *subfonts;  Charset **charsets;};struct _CharCache{  guint ref_count;  CharsetOrdering *ordering;  MaskTable *mask_tables[256];  GIConv converters[MAX_CHARSETS];  PangoCoverage *coverage;};struct _CharCachePointer{  PangoLanguage *lang;  CharCache *cache;};static PangoGlyph conv_8bit (CharCache  *cache,			     GIConv      cd,			     const char *input);static PangoGlyph conv_eucjp (CharCache  *cache,			      GIConv      cd,			      const char *input);static PangoGlyph conv_16bit (CharCache  *cache,			      GIConv      cd,			      const char *input);static PangoGlyph conv_ucs4 (CharCache  *cache,			     GIConv      cd,			     const char *input);static PangoGlyph conv_16bit_MSB_on (CharCache  *cache,			      GIConv      cd,			      const char *input);static PangoGlyph conv_gb18030_1 (CharCache  *cache,			      GIConv      cd,			      const char *input);static PangoGlyph conv_euctw (CharCache  *cache,			      GIConv      cd,			      const char *input);#include "tables-big.i"static PangoEngineScriptInfo basic_scripts[] = {  { PANGO_SCRIPT_COMMON,  "" },};static PangoEngineInfo script_engines[] = {  {    SCRIPT_ENGINE_NAME,    PANGO_ENGINE_TYPE_SHAPE,    PANGO_RENDER_TYPE_X,    basic_scripts, G_N_ELEMENTS(basic_scripts)  }};/* * X window system script engine portion *//* Structure of our cache: * * PangoFont => CharCachePointer  ===\ *                    |               \ *              CharCachePointer  ======> CharCache => CharsetOrdering *                    |                       |======> MaskTable[0]    => {subfonts,charset}[n_subfonts], *                    |                       |======> MaskTable[1]    => {subfonts,charset}[n_subfonts], *                    |                       \======> MaskTable[...]  => {subfonts,charset}[n_subfonts] *                    | *              CharCachePointer  ======> CharCache => CharsetOrdering *                                            |======> MaskTable[0]    => {subfonts,charset}[n_subfonts], *                                            |======> MaskTable[1]    => {subfonts,charset}[n_subfonts], *                                            \======> MaskTable[...]  => {subfonts,charset}[n_subfonts] * * A CharCache structure caches the lookup of what subfonts can be used for what characters for a pair of a Font * and CharsetOrdering. Multiple language tags can share the same CharsetOrdering - the list of CharCachePointer * structures that is attached to the font as object data provides lookups from language tag to charcache. */static CharCache *char_cache_new (CharsetOrdering *ordering){  CharCache *result;  int i;  result = g_new0 (CharCache, 1);  result->ref_count = 1;  result->ordering = ordering;  for (i=0; i<MAX_CHARSETS; i++)    result->converters[i] = (GIConv)-1;  return result;}static voidchar_cache_free (CharCache *cache){  int i;  for (i=0; i<256; i++)    if (cache->mask_tables[i])      {	g_free (cache->mask_tables[i]->subfonts);	g_free (cache->mask_tables[i]->charsets);	g_free (cache->mask_tables[i]);      }  for (i=0; i<MAX_CHARSETS; i++)    if (cache->converters[i] != (GIConv)-1)      g_iconv_close (cache->converters[i]);  g_free (cache);}static PangoGlyphfind_char (CharCache *cache, PangoFont *font, gunichar wc, const char *input){  int mask_index;  MaskTable *mask_table;  int i;  switch (wc)    {    case '\n':    case '\r':    case 0x2028: /* Line separator */    case 0x2029: /* Paragraph separator */      return PANGO_GET_UNKNOWN_GLYPH (wc);      break;    }  if (wc >= G_N_ELEMENTS (char_masks))    mask_index = 0;  else    mask_index = char_masks[wc];  if (cache->mask_tables[mask_index])    mask_table = cache->mask_tables[mask_index];  else    {      const char *charset_names[G_N_ELEMENTS(charsets)];      Charset *charsets_map[G_N_ELEMENTS(charsets)];      guint mask;      int n_charsets = 0;      int *subfont_charsets;      mask_table = g_new (MaskTable, 1);      mask = char_mask_map[mask_index] | ENC_ISO_10646;      /* Find the character sets that are included in this mask       */      for (i=0; i<(int)G_N_ELEMENTS(charsets); i++)	{	  int charset_index = cache->ordering->charsets[i];	  if (mask & (1 << charset_index))	    {	      charset_names[n_charsets] = charsets[charset_index].x_charset;	      charsets_map[n_charsets] = &charsets[charset_index];	      n_charsets++;	    }	}      mask_table->n_subfonts = pango_x_list_subfonts (font, (char**)charset_names, n_charsets, &mask_table->subfonts, &subfont_charsets);      mask_table->charsets = g_new (Charset *, mask_table->n_subfonts);      for (i=0; i<mask_table->n_subfonts; i++)	mask_table->charsets[i] = charsets_map[subfont_charsets[i]];      g_free (subfont_charsets);      cache->mask_tables[mask_index] = mask_table;    }  for (i=0; i < mask_table->n_subfonts; i++)    {      PangoGlyph index;      PangoGlyph glyph;      Charset *charset;      charset = mask_table->charsets[i];      if (charset)	{	  GIConv cd = cache->converters[charset->index];	  if (charset->id && cd == (GIConv)-1)	    {	      cd = g_iconv_open (charset->id, "UTF-8");	      if (cd == (GIConv)-1)		{		  g_warning ("Could not load converter from %s to UTF-8", charset->id);		  mask_table->charsets[i] = NULL;		  continue;		}	      cache->converters[charset->index] = cd;	    }	  index = (*charset->conv_func) (cache, cd, input);	  glyph = PANGO_X_MAKE_GLYPH (mask_table->subfonts[i], index);	  if (pango_x_has_glyph (font, glyph))	    return glyph;	}    }  return 0;}static voidset_glyph (PangoFont *font, PangoGlyphString *glyphs, int i, int offset, PangoGlyph glyph){  PangoRectangle logical_rect;  glyphs->glyphs[i].glyph = glyph;  glyphs->glyphs[i].geometry.x_offset = 0;  glyphs->glyphs[i].geometry.y_offset = 0;  glyphs->log_clusters[i] = offset;  pango_font_get_glyph_extents (font, glyphs->glyphs[i].glyph, NULL, &logical_rect);  glyphs->glyphs[i].geometry.width = logical_rect.width;}static PangoGlyphconv_8bit (CharCache  *cache,	   GIConv      cd,	   const char *input){  char outbuf;  const char *inptr = input;  size_t inbytesleft;  char *outptr = &outbuf;  size_t outbytesleft = 1;  inbytesleft = g_utf8_next_char (input) - input;  g_iconv (cd, (char **)&inptr, &inbytesleft, &outptr, &outbytesleft);  return (guchar)outbuf;}static PangoGlyphconv_eucjp (CharCache  *cache,	    GIConv      cd,	    const char *input){  char outbuf[4];  const char *inptr = input;  size_t inbytesleft;  char *outptr = outbuf;  size_t outbytesleft = 4;  inbytesleft = g_utf8_next_char (input) - input;  g_iconv (cd, (char **)&inptr, &inbytesleft, &outptr, &outbytesleft);  if ((guchar)outbuf[0] < 128)    return outbuf[0];  else if ((guchar)outbuf[0] == 0x8e && outbytesleft == 2)    return ((guchar)outbuf[1]);  else if ((guchar)outbuf[0] == 0x8f && outbytesleft == 1)    return ((guchar)outbuf[1] & 0x7f) * 256 + ((guchar)outbuf[2] & 0x7f);  else    return ((guchar)outbuf[0] & 0x7f) * 256 + ((guchar)outbuf[1] & 0x7f);}static PangoGlyphconv_16bit (CharCache  *cache,	    GIConv      cd,	    const char *input){  char outbuf[2];  const char *inptr = input;  size_t inbytesleft;  char *outptr = outbuf;  size_t outbytesleft = 2;  inbytesleft = g_utf8_next_char (input) - input;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -