Ticket #2715: terminal-width-char.patch

File terminal-width-char.patch, 5.7 KB (added by h.z, 16 years ago)

fix fixed font checking

  • AppearPrefView.cpp

    diff -Naur terminal.orig/AppearPrefView.cpp terminal/AppearPrefView.cpp
    old new  
    1919#include <PopUpMenu.h>
    2020
    2121#include <stdlib.h>
     22#include <stdio.h>
    2223
    2324
    2425AppearancePrefView::AppearancePrefView(BRect frame, const char *name,
     
    170171        if (get_font_family(i, &family, &flags) == B_OK) {
    171172            BFont font;
    172173            font.SetFamilyAndStyle(family, NULL);
    173             if (font.IsFixed()) {
     174            //TODO: checkout this method fit for all fonts
     175            int32 width_ok = 1;
     176            int lastWidth, tmpWidth;
     177            for (int c = 0x20 ; c <= 0x7e; c++){
     178                char buf[4];
     179                sprintf(buf, "%c", c);
     180                tmpWidth = (int)font.StringWidth(buf);
     181                if (c > 0x20 &&(tmpWidth != lastWidth))
     182                    width_ok = 0;
     183                lastWidth = tmpWidth;
     184            }
     185            if (width_ok){
    174186                BMenuItem *item = new BMenuItem(family, new BMessage(command));
    175187                menu->AddItem(item);
    176188                if (!strcmp(defaultFontName, family))
  • BasicTerminalBuffer.cpp

    diff -Naur terminal.orig/BasicTerminalBuffer.cpp terminal/BasicTerminalBuffer.cpp
    old new  
    537537
    538538
    539539void
    540 BasicTerminalBuffer::InsertChar(UTF8Char c, uint32 attributes)
     540BasicTerminalBuffer::InsertChar(UTF8Char c, uint32 width, uint32 attributes)
    541541{
    542542//debug_printf("BasicTerminalBuffer::InsertChar('%.*s' (%d), %#lx)\n",
    543543//(int)c.ByteCount(), c.bytes, c.bytes[0], attributes);
    544     int width = CodeConv::UTF8GetFontWidth(c.bytes);
     544   
     545    //int width = CodeConv::UTF8GetFontWidth(c.bytes);
     546   
    545547    if (width == FULL_WIDTH)
    546548        attributes |= A_WIDTH;
    547549
  • BasicTerminalBuffer.h

    diff -Naur terminal.orig/BasicTerminalBuffer.h terminal/BasicTerminalBuffer.h
    old new  
    9696                                    TermPos& matchEnd) const;
    9797
    9898            // insert chars/lines
    99             void                InsertChar(UTF8Char c, uint32 attributes);
    100     inline  void                InsertChar(const char* c, int32 length,
    101                                     uint32 attributes);
     99    inline  void                InsertChar(UTF8Char c, uint32 attributes);
     100            void                InsertChar(UTF8Char c, uint32 width, uint32 attributes);
     101    inline  void                InsertChar(const char* c, int32 length, uint32 attributes);
     102    inline  void                InsertChar(const char* c, int32 length, uint32 width, uint32 attributes);
    102103            void                InsertCR();
    103104            void                InsertLF();
    104105            void                SetInsertMode(int flag);
     
    208209    return fHistory != NULL ? fHistory->Capacity() : 0;
    209210}
    210211
     212void
     213BasicTerminalBuffer::InsertChar(UTF8Char c, uint32 attributes)
     214{
     215    return InsertChar(c, 1, attributes);
     216}
    211217
    212218void
    213219BasicTerminalBuffer::InsertChar(const char* c, int32 length, uint32 attributes)
    214220{
    215     return InsertChar(UTF8Char(c, length), attributes);
     221    return InsertChar(UTF8Char(c, length), 1, attributes);
    216222}
    217223
     224void
     225BasicTerminalBuffer::InsertChar(const char* c, int32 length, uint32 width, uint32 attributes)
     226{
     227    return InsertChar(UTF8Char(c, length), width, attributes);
     228}
    218229
    219230void
    220231BasicTerminalBuffer::SetCursorX(int32 x)
  • Coding.cpp

    diff -Naur terminal.orig/Coding.cpp terminal/Coding.cpp
    old new  
    3131    {"EUC-jp", "EUCJ", 'E', B_EUC_CONVERSION},
    3232    {"EUC-kr", "EUCK", 'K', B_EUC_KR_CONVERSION},
    3333
     34    {"GB18030", "GB18030", 'G', B_GBK_CONVERSION},
     35    {"Big5", "Big5", 'B', B_BIG5_CONVERSION},
    3436
    3537    /* Not Implemented.
    3638    {"EUC-tw", "EUCT", "T", M_EUC_TW},
  • TermParse.cpp

    diff -Naur terminal.orig/TermParse.cpp terminal/TermParse.cpp
    old new  
    326326    int *groundtable = gUTF8GroundTable;
    327327    int *parsestate = groundtable;
    328328
     329    int width = 1;
    329330    BAutolock locker(fBuffer);
    330331
    331332    while (!fQuitting) {
     
    358359                case B_EUC_CONVERSION:
    359360                case B_EUC_KR_CONVERSION:
    360361                case B_JIS_CONVERSION:
     362                case B_GBK_CONVERSION:
     363                case B_BIG5_CONVERSION:
    361364                    groundtable = gISO8859GroundTable;
    362365                    break;
    363366                case M_UTF8:
     
    379382                /* case iso8859 gr character, or euc */
    380383                ptr = cbuf;
    381384                if (now_coding == B_EUC_CONVERSION || now_coding == B_EUC_KR_CONVERSION
    382                     || now_coding == B_JIS_CONVERSION) {
     385                    || now_coding == B_JIS_CONVERSION || now_coding == B_GBK_CONVERSION
     386                    || now_coding == B_BIG5_CONVERSION) {
    383387                    switch (parsestate[curess]) {
    384388                        case CASE_SS2:      /* JIS X 0201 */
     389                            width = 1;
    385390                            *ptr++ = curess;
    386391                            *ptr++ = c;
    387392                            *ptr = 0;
     
    389394                            break;
    390395
    391396                        case CASE_SS3:      /* JIS X 0212 */
     397                            width = 2;
    392398                            *ptr++ = curess;
    393399                            *ptr++ = c;
    394400                            _NextParseChar(c);
     
    398404                            break;
    399405
    400406                        default:        /* JIS X 0208 */
     407                            width = 2;
    401408                            *ptr++ = c;
    402409                            _NextParseChar(c);
    403410                            *ptr++ = c;
     
    406413                    }
    407414                } else {
    408415                    /* ISO-8859-1...10 and MacRoman */
     416                    width = 1;
    409417                    *ptr++ = c;
    410418                    *ptr = 0;
    411419                }
     
    417425                        B_EUC_CONVERSION);
    418426                }
    419427
    420                 fBuffer->InsertChar(dstbuf, 4, attr);
     428                fBuffer->InsertChar(dstbuf, 4, width, attr);
    421429                break;
    422430
    423431            case CASE_PRINT_CS96:
  • TermView.cpp

    diff -Naur terminal.orig/TermView.cpp terminal/TermView.cpp
    old new  
    10561056                i = lastColumn + 1;
    10571057                continue;
    10581058            }
     1059           
     1060            if (IS_WIDTH(attr))
     1061                count = 2;
     1062            else
     1063                count = 1;
    10591064
    10601065            _DrawLinePart(fFontWidth * i, (int32)_LineOffset(j),
    10611066                attr, buf, count, insideSelection, false, this);