Virtual U.org
Get Personal Training on VU Today
    
Top shadow
 
 register/help
User Name:

Password:

Ofont.cpp Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Ofont.cpp

Go to the documentation of this file.
00001 //Filename    : OFONT.CPP
00002 //Description : Font Object
00003 
00004 #include <OFONT.H>
00005 #include <ALL.H>
00006 #include <IMGFUN.H>
00007 #include <OVGA.H>
00008 #include <OSTR.H>
00009 #include <OSYS.H>
00010 #include <ORES.H>
00011 #include <OINFO.H>
00012 #include <OGAME.H>
00013 #include <OMOUSE.H>
00014 #include <OTRANSL.H>
00015 #include <string.h>
00016 #include <Ostr.h>
00017 
00018 //--------------------------------------------------------//
00019 // A font resource file is composed of three parts :
00020 //
00021 // one FontHeader;
00022 // one FontInfo for each character;
00023 // Bitmap data.
00024 //--------------------------------------------------------//
00025 
00026 //-------- Define struct FontHeader -------//
00027 
00029 struct FontHeader {
00030     unsigned  short max_width;
00031     unsigned short max_height;
00032     unsigned short std_height;
00033     unsigned short first_char;                      // ascii code of the first character
00034     unsigned  short last_char;                      // ascii code of the last character
00035 };
00036 
00037 //-------- Define struct FontInfo -------//
00038 
00040 struct FontInfo {                                 // info for each character
00041     char        offset_y;
00042     unsigned char width;
00043     unsigned char height;
00044     long        bitmap_offset;                      // file offset relative to bitmap data
00045 };
00046 
00047 //--------- Define macro constant ------------//
00048 
00049 #define HYPER_FIELD_COLOR   V_BLUE
00050 
00051 //--------- German character table -------//
00052 
00053 //#ifdef GERMAN
00054 //#define GERMAN_CHAR_COUNT     7
00055 
00056 //      their DOS ascii characters:                      ü    ä    ß    ö    Ä    Ü    Ö
00057 //static short german_ascii_array[]  = { 252, 228, 223, 246, 196, 220, 214 };
00058 //static short german_bmp_id_array[] = { 121, 100,  95, 116, 128, 151, 145 };
00059 //#endif
00060 
00061 //------- Define static member variable --------//
00062 
00063 short      Font::hyper_field_count;
00064 HyperField Font::hyper_field_array[MAX_HYPER_FIELD];
00065 
00066 static int text_line_count;                       // used by text_width() & text_height() only
00067 
00068 //----------- Begin of function Font Constructor -------//
00069 
00070 Font::Font(char* fontName) {
00071     memset( this, 0, sizeof(Font) );
00072 
00073     if( fontName )
00074         init(fontName);
00075 }
00076 
00077 //------------- End of function Font Constructor -------//
00078 
00079 //----------- Begin of function Font Destructor -------//
00080 
00081 Font::~Font() {
00082     deinit();
00083 }
00084 
00085 //------------- End of function Font Destructor -------//
00086 
00087 //-------- Begin of function Font::init -----------//
00101 void Font::init(char* fontName, int interCharSpace, int italicShift) {
00102     if( init_flag )
00103         deinit();
00104 
00105     inter_char_space = interCharSpace;
00106 
00107     //---------- open the font file -----------//
00108 
00109     File fontFile;
00110 
00111     String str;
00112 
00113     str  = DIR_RES;
00114     str += "FNT_";
00115     str += fontName;
00116     str += ".RES";
00117 
00118     fontFile.file_open(str);
00119 
00120     //-------- read in the font header ---------//
00121 
00122     FontHeader fontHeader;
00123 
00124     fontFile.file_read( &fontHeader, sizeof(FontHeader) );
00125 
00126     max_font_width  = fontHeader.max_width;
00127     max_font_height = fontHeader.max_height;
00128     std_font_height = fontHeader.std_height;
00129 
00130     font_height    = std_font_height;               // its default is std_font_height, but can be set to max_font_height
00131 
00132     first_char     = fontHeader.first_char;
00133     last_char    = fontHeader.last_char;
00134 
00135     //----------- read in font info ------------//
00136 
00137     int infoArraySize = sizeof(FontInfo) * (last_char-first_char+1);
00138 
00139     font_info_array = (FontInfo*) mem_add( infoArraySize );
00140 
00141     fontFile.file_read( font_info_array, infoArraySize );
00142 
00143     //------- process italic shift --------//
00144 
00145     if( italicShift ) {
00146         for( int i=0 ; i<last_char-first_char+1 ; i++ )
00147             font_info_array[i].width -= italicShift;
00148     }
00149 
00150     //---------- read in bitmap data ----------//
00151 
00152     int bitmapBufSize = fontFile.file_size() - sizeof(FontHeader) - infoArraySize;
00153 
00154     font_bitmap_buf = mem_add( bitmapBufSize);
00155 
00156     fontFile.file_read( font_bitmap_buf, bitmapBufSize );
00157 
00158     //---- get the width of the space character ----//
00159     //
00160     // since in some font, the space char is too narrow,
00161     // we use the width of 't' as space instead
00162     //
00163     //----------------------------------------------//
00164 
00165     space_width = font_info_array['t'-first_char].width;
00166 
00167     //----------------------------------------------//
00168 
00169     fontFile.file_close();
00170 
00171     init_flag = 1;
00172 }
00173 
00174 //---------- End of function Font::init ----------//
00175 
00176 //----------- Start of function Font::deinit ---------//
00177 //
00178 void Font::deinit() {
00179     if( font_info_array ) {
00180         mem_del( font_info_array );
00181         font_info_array = NULL;
00182     }
00183 
00184     if( font_bitmap_buf ) {
00185         mem_del( font_bitmap_buf );
00186         font_bitmap_buf = NULL;
00187     }
00188 
00189     init_flag = 0;
00190 }
00191 
00192 //------------- End of function Font::deinit ---------//
00193 
00194 //--------- Start of function Font::put ---------//
00195 //
00196 // write text with pre-inited fonts
00197 //
00198 // int x,y         = location of the font
00199 // char* text      = the text to be put on screen
00200 // [int] clearBack = clear background with back_color or not
00201 //                   (default : 0)
00202 // [int]  x2       = display font up to the right border x2 and also
00203 //                   clear the area between the last character and right border
00204 //
00205 // Return : <int> lastX, the x coordination of the last pixel of last font
00206 //
00207 int Font::put(int x,int y,char* textPtr, char clearBack, int x2 ) {
00208     err_when( x<0 || y<0 );
00209 
00210     if( !init_flag )
00211         return x;
00212 
00213     //-------- process translation ---------//
00214 
00215     short textChar;
00216 
00217     textPtr = translate.process(textPtr);
00218 
00219     //-------------------------------------//
00220 
00221     int textPtrLen = strlen(textPtr);
00222 
00223     if( x2 < 0 )                                    // default
00224         x2 = x+max_font_width*textPtrLen;
00225 
00226     x2 = min( x2, VGA_WIDTH-1 );
00227 
00228     if( !Vga::use_back_buf )
00229         mouse.hide_area( x, y, x2, y+font_height );
00230 
00231     int y2 = y+font_height-1;
00232 
00233     //-------------------------------------//
00234 
00235     FontInfo* fontInfo;
00236 
00237     for( int lenCount=1 ; *textPtr && lenCount<=textPtrLen ; textPtr++, lenCount++ ) {
00238         textChar = *((unsigned char*)textPtr);        // textChar is <unsiged char>
00239 
00240         //#ifdef GERMAN
00241         //              textChar = translate_german_char(textChar);
00242         //#endif
00243 
00244         //--------------- space character ------------------//
00245 
00246         if( textChar == ' ' ) {
00247             if( x+space_width > x2 )
00248                 break;
00249 
00250             if( clearBack && !Vga::use_back_buf )       // copy texture from the back buffer as the background color
00251                 vga.blt_buf( x, y, x+space_width-1, y+font_height-1 );
00252 
00253             x += space_width;
00254         }
00255 
00256         //------------- normal character ----------------//
00257 
00258         else if( textChar >= first_char && textChar <= last_char ) {
00259             fontInfo = font_info_array+textChar-first_char;
00260 
00261             if( x+fontInfo->width > x2 )
00262                 break;
00263 
00264             if( fontInfo->width > 0 ) {
00265                 if( clearBack && !Vga::use_back_buf ) {
00266                     if( fontInfo->offset_y > 0 )            // clear the upper space areas of the character
00267                         vga_front.blt_buf_fast( &vga_back, x, y, x+fontInfo->width-1, y+fontInfo->offset_y-1 );
00268 
00269                     vga_front.join_trans( &vga_back, x, y+fontInfo->offset_y, font_bitmap_buf + fontInfo->bitmap_offset );
00270 
00271                     int charHeight = *(((short*)(font_bitmap_buf+fontInfo->bitmap_offset))+1);
00272 
00273                     if( fontInfo->offset_y+charHeight < max_font_height ) {
00274                         int ty1 = y+fontInfo->offset_y+charHeight-1;
00275                         int ty2 = ty1 + max_font_height - (fontInfo->offset_y + charHeight);
00276                         vga_front.blt_buf_fast( &vga_back, x, ty1, x+fontInfo->width-1, ty2 );
00277                     }
00278                 }
00279                 else {
00280                     Vga::active_buf->put_bitmap_trans_fast(x, y+fontInfo->offset_y, font_bitmap_buf + fontInfo->bitmap_offset);
00281                 }
00282 
00283                 x += fontInfo->width;                     // inter-character space
00284             }
00285         }
00286         else {
00287             //------ tab or unknown character -------//
00288 
00289             if( textChar == '\t' )                      // Tab
00290                 x += space_width*8;                       // one tab = 8 space chars
00291             else
00292                 x += space_width;
00293         }
00294 
00295         //--------- inter-character space ---------//
00296 
00297         if( clearBack && !Vga::use_back_buf )         // copy texture from the back buffer as the background color
00298             vga.blt_buf( x, y, x+inter_char_space-1, y+max_font_height-1, 0 );
00299 
00300         x+=inter_char_space;
00301     }
00302 
00303     //------ clear remaining area -------//
00304 
00305     if( clearBack && !Vga::use_back_buf )           // copy texture from the back buffer as the background color
00306         vga.blt_buf( x, y, x2, y+max_font_height-1, 0 );
00307 
00308     if( !Vga::use_back_buf )
00309         mouse.show_area();
00310 
00311     sys.yield();                                    // chwg032799
00312     return x-1;
00313 }
00314 
00315 //----------- End of function Font::put ---------//
00316 
00317 //#ifdef GERMAN
00318 //--------- Start of function Font::translate_german_char ---------//
00319 //
00320 // <char> textChar  = the character to be translated
00321 //
00322 //short Font::translate_german_char(short textChar)
00323 //{
00324 //      for( int i=0 ; i<GERMAN_CHAR_COUNT ; i++ )
00325 //      {
00326 //              if( german_ascii_array[i] == textChar )
00327 //                      return first_char + german_bmp_id_array[i];
00328 //      }
00329 //      return textChar;
00330 //}
00331 //----------- End of function Font::translate_german_char ---------//
00332 //#endif
00333 
00334 //--------- Start of function Font::put_char ---------//
00335 //
00336 // <int>  x, y      = the position of the character
00337 // <char> textChar  = the character
00338 //
00339 void Font::put_char(int x, int y, unsigned short textChar) {
00340     if( textChar >= first_char && textChar <= last_char ) {
00341         FontInfo* fontInfo = font_info_array+textChar-first_char;
00342 
00343         Vga::active_buf->put_bitmap_trans( x, y + fontInfo->offset_y, font_bitmap_buf + fontInfo->bitmap_offset );
00344     }
00345 }
00346 
00347 //----------- End of function Font::put_char ---------//
00348 
00349 //--------- Start of function Font::right_put ---------//
00350 //
00351 // Display a string in right-justified format.
00352 //
00353 // <int>   x, y    = the right end position of displaying the string
00354 // <char*> textPtr = the character
00355 //
00356 void Font::right_put(int x, int y, char* textPtr) {
00357     int textWidth = text_width(textPtr);
00358 
00359     put( x-textWidth, y, textPtr );
00360 }
00361 
00362 //----------- End of function Font::right_put ---------//
00363 
00364 //--------- Begin of function Font::text_width ----//
00378 int Font::text_width(char* textPtr, int textPtrLen, int maxDispWidth) {
00379     int   charWidth, x=0, lenCount, maxLen=0, wordWidth=0;
00380     short textChar;
00381 
00382     if( !init_flag )
00383         return x;
00384 
00385     textPtr = translate.process(textPtr);
00386 
00387     if( textPtrLen < 0 )
00388         textPtrLen = strlen(textPtr);
00389 
00390     text_line_count=1;
00391 
00392     //-------------------------------------//
00393 
00394     for( lenCount=1 ; *textPtr && lenCount<=textPtrLen ; textPtr++, lenCount++, x+=inter_char_space ) {
00395         textChar = *((unsigned char*)textPtr);
00396 
00397         //#ifdef GERMAN
00398         //              textChar = translate_german_char(textChar);
00399         //#endif
00400 
00401         //-- if the line exceed the given max width, advance to next line --//
00402 
00403         if( maxDispWidth && x > maxDispWidth ) {
00404             maxLen = maxDispWidth;
00405             x      = wordWidth;                         // the last word of the prev line wraps to next line
00406             text_line_count++;
00407         }
00408 
00409         //--- if the textPtr has more than 1 line, get the longest line ---//
00410 
00411         if( textChar == '\n' ) {
00412             if( x>maxLen )
00413                 maxLen=x;
00414 
00415             x=0;
00416             wordWidth=0;
00417             text_line_count++;
00418             continue;                                   // next character
00419         }
00420 
00421         //--- add the width of the character to the total line width ---//
00422 
00423         else if( textChar == ' ' ) {
00424             x += space_width;
00425             wordWidth = 0;
00426         }
00427 
00428         else if( textChar >= first_char && textChar <= last_char ) {
00429             charWidth = font_info_array[textChar-first_char].width;
00430 
00431             x         += charWidth;
00432             wordWidth += charWidth;
00433         }
00434         else {
00435             x         += space_width;
00436             wordWidth += space_width;
00437         }
00438 
00439         if( maxDispWidth && wordWidth > maxDispWidth ) {
00440             x         -= wordWidth - maxDispWidth;
00441             wordWidth  = maxDispWidth;
00442         }
00443     }
00444 
00445     //-------------------------------------------//
00446 
00447     if( maxDispWidth && x > maxDispWidth )
00448         text_line_count++;
00449 
00450     if( textPtr[-1] == '\n' )                       // if last character is line feed, don't count double
00451         text_line_count--;
00452 
00453     return max(maxLen,x);
00454 }
00455 
00456 //----------- End of function Font::text_width ----//
00457 
00458 //--------- Begin of function Font::text_height ----//
00468 int Font::text_height(int lineSpace) {
00469     return font_height * text_line_count +
00470         lineSpace   * (text_line_count-1);
00471 }
00472 
00473 //----------- End of function Font::text_height ----//
00474 
00475 //--------- Begin of function Font::put_paragraph ------//
00517 
00518 void Font::put_paragraph(int x1, int y1, int x2, int y2, char *textPtr,
00519                          int lineSpace, int startLine, char dispFlag) {
00520     if( !init_flag || y1+font_height-1 > y2 )
00521         return;
00522 
00523     textPtr = translate.process(textPtr);
00524 
00525     //--------- define vars ---------------//
00526 
00527     int   x,y,wordX;
00528     int   newWord;
00529     short textChar;
00530     char *wordPtr;
00531 
00532     char  flag_under_line=0;                        // attribute control flags
00533     char  flag_large_casa=0;                        // attribute control flags
00534     char  flag_hyper_field=0;
00535 
00536     int   under_line_x1;                            // parameters for drawing under line
00537 
00538     HyperField* hyper_field_ptr = hyper_field_array;
00539     FontInfo*   fontInfo;
00540 
00541   //--------- initialize vars ---------------//
00542 
00543     x       = x1;
00544     y       = y1;
00545     wordX   = x1;                                   // the x of the start of the word
00546     wordPtr = textPtr;
00547     newWord = 0;
00548 
00549     line_count=0;
00550 
00551     hyper_field_count = 0;
00552 
00553     //---------- prepare for display font ----------//
00554 
00555     if( dispFlag ) {
00556         err_when( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT );
00557 
00558         if( !Vga::use_back_buf )                      // if not say word by word, turn off mouse one time, otherwise turn off mouse one word at a time
00559             mouse.hide_area( x1,y1,x2,y2 );             // if the mouse cursor is in that area, hide it
00560     }
00561 
00562     //--------- loop for displaying textPtr ----------//
00563 
00564     while(1) {
00565         //------ space appear, process the previous word ------//
00566         if ( newWord ) {
00567             if( x-1 > x2 ) {                            // it is still okay if x-1==x2 because x is the next pixel, not the last displayed pixel
00568                 if( line_count >= startLine-1 ) {         // startLine start from 1
00569                     y += font_height + lineSpace;
00570                     if ( y + font_height - 1 > y2 )         // no further space for printing textPtr, end
00571                         break;
00572                 }
00573 
00574                 x = x1;
00575                 line_count++;
00576             }
00577             else {
00578                 x = wordX;
00579             }
00580 
00581             //--------- Process current word ----------//
00582 
00583             // wordPtr point to the current word which will be printed
00584             for( ; wordPtr < textPtr && *wordPtr ; wordPtr++, x+=inter_char_space ) {
00585                 textChar = *((unsigned char*)wordPtr);    // textChar is <unsiged char>
00586 
00587                 //#ifdef GERMAN
00588                 //                              textChar = translate_german_char(textChar);
00589                 //#endif
00590 
00591                 //---------- control char: '_' -------------//
00592 
00593                 if( textChar == '_' ) {                   // e.g. _Title_, a line will be drawn under the word "Title"
00594                     if( flag_under_line ) {                 // current '_' is the closing one, the open '_' has appeared previously
00595                         // startLine start from 1
00596                         if( dispFlag && line_count >= startLine-1 )
00597                             if( flag_large_casa ) {
00598                                 // ## begin chwg 1016
00599                                 Vga::active_buf->bar_fast(under_line_x1, y+font_casa.
00600                                                           font_height, x, y+font_casa.font_height, HYPER_FIELD_COLOR );
00601                             }
00602                             else
00603                                 Vga::active_buf->bar_fast(under_line_x1, y+font_height, x, y+font_height, HYPER_FIELD_COLOR );
00604                     }
00605                     else
00606                         under_line_x1 = x;
00607 
00608                     flag_under_line = !flag_under_line;
00609                     continue;
00610                 }
00611 
00612                 if( textChar == '^' ) {                   // e.g. _Title_, a line will be drawn under the word "Title"
00613                     flag_large_casa = !flag_large_casa;
00614                     continue;
00615                 }
00616 
00617                 //-------- control char: '~' -----------//
00618 
00619                 else if( textChar == '~' ) {              // e.g. ~Captial~, the word "Capital" is a hyper-textPtred field, pressing on it will link to the topic "Capital"
00620                     if( !flag_hyper_field ) {               // current '~' is the opening one
00621                         hyper_field_ptr->x1       = x;
00622                         hyper_field_ptr->y1       = y;
00623                         // skip current '~'
00624                         hyper_field_ptr->text_ptr = (wordPtr+1);
00625                     }
00626                     else {                                  // current '~' is the closing one
00627                         hyper_field_ptr->x2       = x;
00628                         hyper_field_ptr->y2       = y+font_height;
00629                         hyper_field_ptr->text_len = wordPtr - hyper_field_ptr->text_ptr;
00630 
00631                         hyper_field_count++;
00632                         hyper_field_ptr++;
00633                         err_when( hyper_field_count >= MAX_HYPER_FIELD );
00634                     }
00635 
00636                     flag_hyper_field = !flag_hyper_field;
00637                     continue;
00638                 }
00639 
00640                 //--------------- space character ------------------//
00641 
00642                 else if( textChar == ' ' ) {
00643                     if(*(wordPtr-1)!=' ')
00644                         if(*(wordPtr+1)==' ')
00645                             break;
00646                     if( x+space_width > x2 )
00647                         break;
00648 
00649                     x += space_width;
00650                 }
00651 
00652                 //----------- display char ------------//
00653 
00654                 else if( textChar >= first_char && textChar <= last_char ) {
00655                     FontInfo* oldfontInfo = font_info_array+textChar-first_char;
00656 
00657                     // character width = offset of next character - current offset
00658 
00659                     // fix in version 2
00660                     // if( x2 >= 0 && x+fontInfo->width-1 > x2 )      // exceed right border x2
00661                     // exceed right border x2
00662                     if( x2 >= 0 && x+oldfontInfo->width-1 > x2 )
00663                         break;
00664 
00665                     // fix in version 2
00666                     // if( fontInfo->width > 0 )
00667                     if( oldfontInfo->width > 0 ) {
00668                         // fix in version 2
00669                         //if( dispFlag && line_count >= startLine-1 )    // startLine start from 1
00670                         //{
00671                         if( flag_hyper_field ) {
00672                             // ## begin chwg 1016
00673                             fontInfo = font_blue_san.font_info_array+textChar-first_char;
00674                             if( dispFlag && line_count >= startLine-1 )
00675                                 font_blue_san.put_char(x,y,textChar);
00676                         }
00677                         else if( flag_large_casa ) {
00678                             // ## begin chwg 1016
00679                             fontInfo = font_casa.font_info_array+textChar-first_char;
00680                             if( dispFlag && line_count >= startLine-1 )
00681                                 font_casa.put_char(x,y,textChar);
00682                         }
00683                         else {
00684                             fontInfo = oldfontInfo;
00685                             if( dispFlag && line_count >= startLine-1 )
00686                                 Vga::active_buf->put_bitmap_trans_fast(x, y+fontInfo->offset_y,
00687                                                                        font_bitmap_buf + fontInfo->bitmap_offset);
00688                         }
00689 
00690                         //}
00691                         x += fontInfo->width;
00692                         // ## end chwg 1016
00693 
00694                     }
00695                 }
00696             }
00697 
00698             //--------- next line ----------------------//
00699 
00700             if( *textPtr == '\n' ) {                    // next line
00701                 if( line_count >= startLine-1 ) {         // startLine start from 1
00702                     y += font_height + lineSpace;
00703                     if ( y + font_height - 1 > y2 )         // no further space for printing textPtr, end
00704                         break;
00705                 }
00706 
00707                 x = x1;
00708                 textPtr++;
00709                 line_count++;
00710             }
00711 
00712             if( *textPtr == NULL )                      // all paragraph has been printed
00713                 break;
00714 
00715             wordPtr = textPtr;
00716             wordX   = x;
00717             newWord = 0;
00718         }
00719 
00720         //------------ process spacing -------------//
00721 
00722         // not space
00723         if( *textPtr == ' ' || *textPtr == '\n' || *textPtr == NULL )
00724             newWord = 1;
00725         else {
00726             textChar = *((unsigned char*)textPtr);      // textChar is <unsiged char>
00727 
00728             //#ifdef GERMAN
00729             //                  textChar = translate_german_char(textChar);
00730             //#endif
00731 
00732             if( textChar >= first_char && textChar <= last_char ) {
00733                 fontInfo = font_info_array+textChar-first_char;
00734 
00735                 if( textChar == ' ' )
00736                     x+=space_width;
00737 
00738                 else if( fontInfo->width > 0 )            // current font width
00739                     x+=fontInfo->width;
00740 
00741                 else
00742                     x+=space_width;
00743             }
00744             else {
00745                 x+=space_width;
00746             }
00747 
00748             x+=inter_char_space;
00749         }
00750 
00751         if( *textPtr && *textPtr != '\n' )            // when finished, remain as NULL for next cycle to detect
00752             textPtr++;
00753     }
00754 
00755     //------------ finish displaying ----------------//
00756 
00757     if( dispFlag ) {
00758         if( !Vga::use_back_buf )
00759             mouse.show_area();
00760     }
00761 
00762     //   while( *textPtr == '\n' || *textPtr == '\r' )
00763     //      textPtr++;
00764 
00765     next_text_ptr = textPtr;                        // the current pointer in the textPtr
00766     next_text_y   = y + font_height + lineSpace;
00767     line_count++;
00768 }
00769 
00770 //---------- End of function Font::put_paragraph ------//
00771 
00772 //--------- Begin of function Font::find_splitter ------//
00777 int Font::find_splitter(int area_width, int start_char, char *textPtr) {
00778     String str=textPtr;
00779     int width_measure=0;
00780     int last_splitter=start_char;
00781     int i=start_char;
00782     while(width_measure<area_width&&str[i]!=NULL) {
00783         if(str[i]=='\n'||str[i]==' '||str[i]==NULL)
00784             last_splitter=i;
00785 
00786         if( str[i] >= first_char && str[i] <= last_char ) {
00787             int charWidth = font_info_array[str[i]-first_char].width;
00788             if(str[i]==' ')charWidth=space_width;
00789             width_measure += charWidth;
00790         }
00791         i++;
00792     }
00793 
00794     if(str[i]==NULL)
00795         last_splitter=i;
00796 
00797     return last_splitter;
00798 }
00799 
00800 //---------- End of function Font::find_splitter ------//
00801 
00802 //--------- Begin of function Font::get_line ------//
00807 char* Font::get_line(int area_width, int line, char *textPtr) {
00808     int ptr1,ptr2;
00809     String str=textPtr;
00810 
00811     ptr1=0;
00812 
00813     for(int i=0;i<line;i++) {
00814         ptr2=find_splitter(area_width, ptr1, str.str_buf);
00815         if(i==line-1)
00816             return str.substr(ptr1,ptr2-ptr1);
00817         ptr1=ptr2+1;
00818     }
00819     return NULL;
00820 }
00821 
00822 //---------- End of function Font::find_splitter ------//
00823 
00824 //--------- Begin of function Font::count_line ------//
00828 int Font::count_line(int area_width, char *textPtr) {
00829     int ptr1,ptr2,line;
00830     String str=textPtr;
00831 
00832     ptr1=0;
00833     ptr2=-1;
00834     line=0;
00835     while(1) {
00836         ptr2=find_splitter(area_width, ptr1, str.str_buf);
00837         if(ptr1==ptr2)break;
00838         ptr1=ptr2+1;
00839         line++;
00840     }
00841     return line;
00842 }
00843 
00844 //---------- End of function Font::find_splitter ------//
00845 
00846 //--------- Begin of function Font::count_line ------//
00859 void Font::count_line(int x1, int y1, int x2, int y2, char *textPtr,
00860                       int lineSpace , int& dispLines, int& totalLines) {
00861     dispLines =0;
00862     totalLines=0;
00863 
00864     while( *textPtr ) {                             // if *textPtr==NULL means EOF
00865         // last 0-means don't display the textPtr, only returning the parameters for our calculating of line counts
00866         put_paragraph(x1, y1, x2, y2, textPtr, lineSpace, 1, 0);
00867 
00868         if( !dispLines )                              // only set once at the first time
00869             dispLines = line_count;
00870 
00871         totalLines += line_count;
00872         textPtr     = next_text_ptr;
00873     }
00874 }
00875 
00876 //---------- End of function Font::count_line ------//
00877 
00878 //-------- Begin of function Font::d3_put --------//
00887 int Font::d3_put(int x1, int y1, char* desStr ) {
00888     int marginSpace = font_height/5;
00889 
00890     int x2 = x1+text_width(desStr)+marginSpace*2-1;
00891 
00892     vga.active_buf->d3_panel_up( x1, y1, x2, y1+font_height+marginSpace*2-1 );
00893 
00894     put( x1+marginSpace, y1+marginSpace, desStr);
00895 
00896     return x2;
00897 }
00898 
00899 //--------- End of function Font::d3_put ---------//
00900 
00901 //-------- Begin of function Font::d3_put --------//
00910 void Font::d3_put(int x1, int y1, int x2, int y2, char* desStr) {
00911     int tx = x1 + ((x2-x1+1) - text_width(desStr))/2;
00912     int ty = y1 + ((y2-y1+1) - font_height)/2+1;
00913 
00914     vga.active_buf->d3_panel_up( x1, y1, x2, y2);
00915 
00916     if( tx<x1+2 )
00917         tx=x1+2;
00918 
00919     put( tx, ty, desStr, 0, x2-2 );
00920 }
00921 
00922 //--------- End of function Font::d3_put ---------//
00923 
00924 //-------- Begin of function Font::center_put --------//
00936 int Font::center_put(int x1, int y1, int x2, int y2, char* desStr, char clearBack) {
00937     int tx = x1 + ((x2-x1+1) - text_width(desStr))/2;
00938     int ty = y1 + ((y2-y1+1) - font_height)/2;
00939 
00940     if( tx<0 )
00941         tx=0;
00942 
00943     if( clearBack && !Vga::use_back_buf && tx>x1 )  // copy texture from the back buffer as the background color
00944         vga.blt_buf( x1, y1, tx-1, y2 );
00945 
00946     return put( tx, ty, desStr, clearBack, x2 );
00947 }
00948 
00949 //--------- End of function Font::center_put ---------//
00950 
00951 //-------- Begin of function Font::put_field --------//
00967 void Font::put_field(int x1, int y1, char* desStr, int x2, int value, int format ) {
00968     vga.active_buf->d3_panel_up( x1, y1, x2, y1+font_height+3 );
00969 
00970     put( x1+4, y1+2, desStr);
00971     put( x2+4, y1+2, m.format(value,format) );
00972 }
00973 
00974 //--------- End of function Font::put_field ---------//
00975 
00976 //-------- Begin of function Font::update_field --------//
00991 void Font::update_field(int x1, int y1, int value, int format, int x2) {
00992     if( x2<0 )
00993         x2 = x1+80;
00994 
00995     put( x1+4, y1+2, m.format(value,format), 1, x2 );
00996 }
00997 
00998 //--------- End of function Font::update_field ---------//
00999 
01000 //-------- Begin of function Font::field --------//
01020 void Font::field(int xDes, int y1, char* desStr, int xValue, int value,
01021                  int format, int xEnd, int refreshFlag, char* helpCode) {
01022     int x2;
01023 
01024     if( refreshFlag == INFO_REPAINT ) {
01025         vga.active_buf->d3_panel_up( xDes, y1, xValue, y1+font_height+3 );
01026 
01027         put( xDes+4  , y1+2, desStr);
01028         x2 = put( xValue+4, y1+2, m.format(value,format) );
01029     }
01030     else {
01031         vga.active_buf->d3_panel_up( xDes, y1, xValue, y1+font_height+3 );
01032         put( xDes+4  , y1+2, desStr);
01033         x2 = put( xValue+4, y1+2, m.format(value,format), 1, xEnd );
01034     }
01035 
01036     //  if( helpCode )
01037     //          help.set_help(xDes, y1, x2, y1+font_height+3, helpCode );
01038 }
01039 
01040 //--------- End of function Font::field ---------//
01041 
01042 //-------- Begin of function Font::put_field --------//
01058 void Font::put_field(int x1, int y1, char* desStr, int x2, double value, int format) {
01059     vga.active_buf->d3_panel_up( x1, y1, x2, y1+font_height+3 );
01060 
01061     put( x1+4, y1+2, desStr);
01062     put( x2+4, y1+2, m.format(value,format) );
01063 }
01064 
01065 //--------- End of function Font::put_field ---------//
01066 
01067 //-------- Begin of function Font::update_field --------//
01082 void Font::update_field(int x1, int y1, double value, int format, int x2) {
01083     if( x2<0 )
01084         x2 = x1+80;
01085 
01086     put( x1+4, y1+2, m.format(value,format), 1, x2 );
01087 }
01088 
01089 //--------- End of function Font::update_field ---------//
01090 
01091 //-------- Begin of function Font::field --------//
01111 void Font::field(int xDes, int y1, char* desStr, int xValue, double value,
01112                  int format, int xEnd, int refreshFlag, char* helpCode ) {
01113     int x2;
01114 
01115     if( refreshFlag == INFO_REPAINT ) {
01116         vga.active_buf->d3_panel_up( xDes, y1, xValue, y1+font_height+3 );
01117 
01118         put( xDes+4  , y1+2, desStr);
01119         x2 = put( xValue+4, y1+2, m.format(value,format) );
01120     }
01121     else {
01122         vga.active_buf->d3_panel_up( xDes, y1, xValue, y1+font_height+3 );
01123 
01124         put( xDes+4  , y1+2, desStr);
01125         x2 = put( xValue+4, y1+2, m.format(value,format), 1, xEnd );
01126     }
01127 
01128     //  if( helpCode )
01129     //          help.set_help(xDes, y1, x2, y1+font_height+3, helpCode );
01130 }
01131 
01132 //--------- End of function Font::field ---------//
01133 
01134 //-------- Begin of function Font::put_field --------//
01145 void Font::put_field(int x1, int y1, char* desStr, int x2, char* value) {
01146     vga.active_buf->d3_panel_up( x1, y1, x2, y1+font_height+3 );
01147 
01148     put( x1+4, y1+2, desStr);
01149     put( x2+4, y1+2, value);
01150 }
01151 
01152 //--------- End of function Font::put_field ---------//
01153 
01154 //-------- Begin of function Font::update_field --------//
01163 void Font::update_field(int x1, int y1, char* value, int x2) {
01164     if( x2<0 )
01165         x2 = x1+80;
01166 
01167     put( x1+4, y1+2, value, 1, x2 );
01168 }
01169 
01170 //--------- End of function Font::update_field ---------//
01171 
01172 //-------- Begin of function Font::field --------//
01188 void Font::field(int xDes, int y1, char* desStr, int xValue, char* value,
01189                  int xEnd, int refreshFlag, char* helpCode ) {
01190     int x2;
01191 
01192     if( refreshFlag == INFO_REPAINT ) {
01193         vga.active_buf->d3_panel_up( xDes, y1, xValue, y1+font_height+3 );
01194 
01195         put( xDes+4  , y1+2, desStr);
01196         x2 = put( xValue+4, y1+2, value );
01197     }
01198     else {
01199         vga.active_buf->d3_panel_up( xDes, y1, xValue, y1+font_height+3 );
01200 
01201         put( xDes+4  , y1+2, desStr);
01202         x2 = put( xValue+4, y1+2, value, 1, xEnd );
01203     }
01204 
01205     //  if( helpCode )
01206     //          help.set_help(xDes, y1, x2, y1+font_height+3, helpCode );
01207 }
01208 
01209 //--------- End of function Font::field ---------//
01210 
01211 //-------- Begin of function Font::disp --------//
01227 int Font::disp(int x1, int y1, int value, int format, int x2) {
01228     if( x2<0 )
01229         x2 = x1+80;
01230 
01231     int lastX = put( x1, y1, m.format(value,format), 1, x2 );
01232 
01233     return lastX;
01234 }
01235 
01236 //--------- End of function Font::disp ---------//
01237 
01238 //-------- Begin of function Font::disp --------//
01254 int Font::disp(int x1, int y1, double value, int format, int x2) {
01255     if( x2<0 )
01256         x2 = x1+80;
01257 
01258     int lastX = put( x1, y1, m.format(value,format), 1, x2 );
01259 
01260     return lastX;
01261 }
01262 
01263 //--------- End of function Font::disp ---------//
01264 
01265 //-------- Begin of function Font::disp --------//
01275 int Font::disp(int x1, int y1, char* textPtr, int x2) {
01276     if( x2<0 )
01277         x2 = x1+80;
01278 
01279     int lastX = put( x1, y1, textPtr, 1, x2 );
01280 
01281     return lastX;
01282 }
01283 
01284 //--------- End of function Font::disp ---------//
01285 
01286 //--------- Begin of function Font::put_char_to_buffer ---------//
01287 void Font::put_char_to_buffer(char* dest, int destPitch, int x, int y, unsigned short textChar) {
01288     if( textChar >= first_char && textChar <= last_char ) {
01289         FontInfo* fontInfo = font_info_array+textChar-first_char;
01290         char *fontBitmap = font_bitmap_buf + fontInfo->bitmap_offset;
01291 
01292         err_here();                                   // 8-8 bit not supported
01293         // IMGbltTrans( dest, destPitch, x, y + fontInfo->offset_y, fontBitmap );
01294     }
01295 }
01296 
01297 //--------- End of function Font::put_char_to_buffer ---------//
01298 
01299 //--------- Begin of function Font::put_to_buffer ---------//
01300 void Font::put_to_buffer(char* dest, int destPitch, int x1, int y1, char *text) {
01301     int x2 = destPitch;                             // width of buffer
01302     while( *text != '\0' && x1 < x2) {
01303         int charSize = sizeof(unsigned char);         // 1 for byte character, 2 for word character
01304         unsigned short textChar = *(unsigned char *)text;
01305 
01306         //#ifdef GERMAN
01307         //              textChar = translate_german_char(textChar);
01308         //#endif
01309 
01310         //if( // unicode or a word character )
01311         //{
01312         //      textChar = *(unsigned short *)buffer;                   // unicode
01313         // textChar = *(unsigned char *)text << 8 + *(1+(unsigned char *)text); // big-5...
01314         //      charSize = sizeof(unsigned short);
01315         //}
01316 
01317         // --------- advance to next character------------//
01318 
01319         int charWidth = textChar == ' ' ? space_width :
01320             (font_info_array+textChar-first_char)->width;
01321 
01322         if( x1 + charWidth <= x2 )
01323             put_char_to_buffer( dest, destPitch, x1, y1, textChar);
01324 
01325         x1 += charWidth;
01326         text += charSize;
01327     }
01328 }
01329 
01330 //--------- End of function Font::put_to_buffer ---------//
01331 
01332 //--------- Begin of function Font::center_put_to_buffer ---------//
01333 void Font::center_put_to_buffer(char* dest, int destPitch, int x1, int y1, int x2, int y2, char *desStr) {
01334     int tx = x1 + ((x2-x1) - text_width(desStr))/2;
01335     int ty = y1 + ((y2-y1) - font_height)/2;
01336 
01337     if( tx<0 )
01338         tx=0;
01339 
01340     put_to_buffer( dest, destPitch, tx, ty, desStr);
01341 }
01342 
01343 //--------- End of function Font::center_put_to_buffer ---------//
01344 
01345 //--------- Begin of function Font::put_char_to_bufferW ---------//
01346 void Font::put_char_to_bufferW(short* dest, int destPitch, int x, int y, unsigned short textChar) {
01347     if( textChar >= first_char && textChar <= last_char ) {
01348         FontInfo* fontInfo = font_info_array+textChar-first_char;
01349         char *fontBitmap = font_bitmap_buf + fontInfo->bitmap_offset;
01350 
01351         IMGbltTransRemap( dest, destPitch, x, y + fontInfo->offset_y, fontBitmap, vga.default_remap_table );
01352     }
01353 }
01354 
01355 //--------- End of function Font::put_char_to_bufferW ---------//
01356 
01357 //--------- Begin of function Font::put_to_bufferW ---------//
01358 void Font::put_to_bufferW(short* dest, int destPitch, int x1, int y1, char *text) {
01359     int x2 = destPitch;                             // width of buffer
01360     while( *text != '\0' && x1 < x2) {
01361         int charSize = sizeof(unsigned char);         // 1 for byte character, 2 for word character
01362         unsigned short textChar = *(unsigned char *)text;
01363 
01364         // --------- advance to next character------------//
01365 
01366         int charWidth = textChar == ' ' ? space_width :
01367             (font_info_array+textChar-first_char)->width;
01368 
01369         if( x1 + charWidth <= x2 )
01370             put_char_to_bufferW( dest, destPitch, x1, y1, textChar);
01371 
01372         x1 += charWidth;
01373         text += charSize;
01374     }
01375 }
01376 
01377 //--------- End of function Font::put_to_bufferW ---------//
01378 
01379 //--------- Begin of function Font::center_put_to_bufferW ---------//
01380 void Font::center_put_to_bufferW(short* dest, int destPitch, int x1, int y1, int x2, int y2, char *desStr) {
01381     int tx = x1 + ((x2-x1) - text_width(desStr))/2;
01382     int ty = y1 + ((y2-y1) - font_height)/2;
01383 
01384     if( tx<0 )
01385         tx=0;
01386 
01387     put_to_bufferW( dest, destPitch, tx, ty, desStr);
01388 }
01389 
01390 //--------- End of function Font::center_put_to_bufferW ---------//

Generated on Fri Aug 23 01:37:41 2002 for VirtualU by doxygen1.2.17