/*--------------------------------*-C-*---------------------------------* * File: thai.c *----------------------------------------------------------------------* * * All portions of code are copyright by their respective author/s. * Copyright (C) 2000,2001 Teepanis Chachiyo * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *---------------------------------------------------------------------*/ #include "rxvt.h" #include "thai.h" #ifdef THAI #if defined (NO_BRIGHTCOLOR) || defined (VERYBOLD) # define MONO_BOLD(x) ((x) & (RS_Bold|RS_Blink)) #else # define MONO_BOLD(x) (((x) & RS_Bold) && fore == Color_fg) #endif /* * ThaiIsMiddleLineCh returns TRUE if character 'ch' * is to be displayed in the middle line. */ /* PROTO */ int ThaiIsMiddleLineCh(char ch) { if(thai_map[(unsigned char)ch]==0) return 1; else return 0; } /* * ThaiPixel2Col converts x-y coordiates in pixel * into byte offset that store character data. * This function replaces Pixel2Col in orinal * ATERM. */ /* PROTO */ int ThaiPixel2Col(int x, int y) { int row; /* row storing data */ int i; /* byte offset index */ int xpixel; /* dummy x pixel */ char *str; /* drawn_text pointer */ XFontStruct *wf; /* font */ /* locate buffer storing data */ row = Pixel2Row(y); MAX_IT(row, 0); MIN_IT(row, TermWin.nrow - 1); str = drawn_text[row]; /* access to font structure */ wf = TermWin.font; /* increase byte offset until we get to target x */ i = 0; xpixel = CharWidth(wf,str[0]); x -= TermWin_internalBorder; while(xpixel <= x && i < TermWin.ncol){ i++; xpixel += CharWidth(wf,str[i]); /* wf->per_char[char_num].width; */ } MAX_IT(i, 0); MIN_IT(i, TermWin.ncol); return i; } /* * ThaiCol2Pixel returns x cooridate of Thai strings. * It also adjusts the to the upper/lowwer Thai character. * This replaces Col2Pixel and is called repeatedly so * I use 'static' variable to speed it up. */ /* PROTO */ int ThaiCol2Pixel(int col, char *start) /* * TODO: Still have some problem with scaled font */ { static int i=0; /* index */ static char *laststart=NULL; /* strings from last call */ static unsigned int x=0; /* x coordinate for proportional font */ static XFontStruct *wf; /* font */ /* new string, so restart from the beginning */ if(laststart!=start || col < i){ i=0; x=TermWin_internalBorder; laststart=start; wf = TermWin.font; } /* old string, continue counting */ for(; i < col; i++){ x+= CharWidth(wf,start[i]); } return x; } /* PROTO */ int ThaiUpdateMap2(text_t *stp, text_t *dtp, rend_t *srp, rend_t *drp, char *map, int len) { int stpx, dtpx; /* xpixel position of screen & drawntext */ int stpi, dtpi; int char_num; XFontStruct *wf; wf = TermWin.font; stpx = dtpx = 0; stpi = dtpi = 0; for(stpi = 0; stpi < len;stpi++, char_num = (unsigned char)stp[stpi]-wf->min_char_or_byte2, stpx += wf->per_char[char_num].width){ while(dtpx < stpx && dtpi < len-1){ dtpi++; char_num = (unsigned char)dtp[dtpi]-wf->min_char_or_byte2; dtpx+= wf->per_char[char_num].width; } map[stpi] = (stp[stpi]==dtp[dtpi] && srp[stpi]==drp[dtpi]) ? 0 : 1; } return 0; } /* * ThaiUpdateMap decides which character should be redraw on * screen. It returns the number of characters to update. * The algorithm is follow: * (1) At current Thai column, check if all characters at * this column is the same * (2) If yes, no need to update * (3) If no, update entire Thai column * (4) go to next Thai column, --> (1) */ /* PROTO */ int ThaiUpdateMap(text_t *stp, text_t *dtp, rend_t *srp, rend_t *drp, char *map, int len) { int stp_col=0, dtp_col=0; /* index */ int stp_lev=0, dtp_lev=0; /* # of characters at the column */ int i=0,match=0; /* matching flag */ int lastbold=0; /* BOLD_OVERSTRIKE feature */ int nupdate; /* # chars to update */ nupdate = len; /* update by default */ for(i=0;i=0 && thai_map[(unsigned char)stp[i]]!=0;i--) map[i]=1; return 0; } /* * Thai_ColMaxPaint finds the truncated spaces needed to * paint strings str on screen. */ /* PROTO */ int Thai_ColMaxPaint(text_t *str, int len) { int i, col=0; /* truncate end space */ for(i = len-1; i>=0 && str[i]==' '; i--); for(; i>=0; i--) if(ThaiIsMiddleLineCh(str[i])) col++; return col; } #endif /* #ifdef THAI */