diff --git a/src/apps/terminal/AppearPrefView.cpp b/src/apps/terminal/AppearPrefView.cpp index d6b4a6421d..d357d84471 100644 --- a/src/apps/terminal/AppearPrefView.cpp +++ b/src/apps/terminal/AppearPrefView.cpp @@ -18,9 +18,34 @@ #include #include +#include #include +static bool +IsFontUsable(const BFont &font) +{ + // TODO: If BFont::IsFullAndHalfFixed() was implemented, we could + // use that. But I don't think it's easily implementable using + // Freetype. + + if (font.IsFixed()) + return true; + + bool widthOk = true; + int lastWidth; + for (int c = 0x20 ; c <= 0x7e; c++){ + char buf[4]; + snprintf(buf, sizeof(buf), "%c", c); + int tmpWidth = (int)font.StringWidth(buf); + if (c > 0x20 &&(tmpWidth != lastWidth)) + widthOk = false; + lastWidth = tmpWidth; + } + return widthOk; +} + + AppearancePrefView::AppearancePrefView(BRect frame, const char *name, BMessenger messenger) : PrefView(frame, name), @@ -170,7 +195,7 @@ AppearancePrefView::_MakeFontMenu(uint32 command, const char *defaultFontName) if (get_font_family(i, &family, &flags) == B_OK) { BFont font; font.SetFamilyAndStyle(family, NULL); - if (font.IsFixed()) { + if (IsFontUsable(font)) { BMenuItem *item = new BMenuItem(family, new BMessage(command)); menu->AddItem(item); if (!strcmp(defaultFontName, family)) diff --git a/src/apps/terminal/BasicTerminalBuffer.cpp b/src/apps/terminal/BasicTerminalBuffer.cpp index eb0f5f41ed..174de9fa69 100644 --- a/src/apps/terminal/BasicTerminalBuffer.cpp +++ b/src/apps/terminal/BasicTerminalBuffer.cpp @@ -537,11 +537,12 @@ BasicTerminalBuffer::Find(const char* _pattern, const TermPos& start, void -BasicTerminalBuffer::InsertChar(UTF8Char c, uint32 attributes) +BasicTerminalBuffer::InsertChar(UTF8Char c, uint32 width, uint32 attributes) { //debug_printf("BasicTerminalBuffer::InsertChar('%.*s' (%d), %#lx)\n", //(int)c.ByteCount(), c.bytes, c.bytes[0], attributes); - int width = CodeConv::UTF8GetFontWidth(c.bytes); + // TODO: Check if this method can be removed completely + //int width = CodeConv::UTF8GetFontWidth(c.bytes); if (width == FULL_WIDTH) attributes |= A_WIDTH; diff --git a/src/apps/terminal/BasicTerminalBuffer.h b/src/apps/terminal/BasicTerminalBuffer.h index 3372bcbb0f..cc1aaf5dc3 100644 --- a/src/apps/terminal/BasicTerminalBuffer.h +++ b/src/apps/terminal/BasicTerminalBuffer.h @@ -96,9 +96,14 @@ public: TermPos& matchEnd) const; // insert chars/lines - void InsertChar(UTF8Char c, uint32 attributes); - inline void InsertChar(const char* c, int32 length, - uint32 attributes); + inline void InsertChar(UTF8Char c, uint32 attributes); + void InsertChar(UTF8Char c, uint32 width, + uint32 attributes); + inline void InsertChar(const char* c, int32 length, + uint32 attributes); + inline void InsertChar(const char* c, int32 length, + uint32 width, uint32 attributes); + void InsertCR(); void InsertLF(); void SetInsertMode(int flag); @@ -209,10 +214,24 @@ BasicTerminalBuffer::HistoryCapacity() const } +void +BasicTerminalBuffer::InsertChar(UTF8Char c, uint32 attributes) +{ + return InsertChar(c, 1, attributes); +} + + void BasicTerminalBuffer::InsertChar(const char* c, int32 length, uint32 attributes) { - return InsertChar(UTF8Char(c, length), attributes); + return InsertChar(UTF8Char(c, length), 1, attributes); +} + + +void +BasicTerminalBuffer::InsertChar(const char* c, int32 length, uint32 width, uint32 attributes) +{ + return InsertChar(UTF8Char(c, length), width, attributes); } diff --git a/src/apps/terminal/CodeConv.cpp b/src/apps/terminal/CodeConv.cpp index 18c8652ecf..d7fa9fbeeb 100644 --- a/src/apps/terminal/CodeConv.cpp +++ b/src/apps/terminal/CodeConv.cpp @@ -38,7 +38,6 @@ extern char gUTF8WidthTable[]; // defined in UTF8WidthTbl.c int32 CodeConv::UTF8GetFontWidth(const char *string) { - return 1; ushort unicode = UTF8toUnicode(string); uchar width = gUTF8WidthTable[unicode >> 3]; ushort offset = unicode & 0x07; diff --git a/src/apps/terminal/Coding.cpp b/src/apps/terminal/Coding.cpp index c2fecb4dd6..899e09f461 100644 --- a/src/apps/terminal/Coding.cpp +++ b/src/apps/terminal/Coding.cpp @@ -30,11 +30,11 @@ const static etable kEncodingTable[] = {"Shift-JIS", "SJIS", 'S', B_SJIS_CONVERSION}, {"EUC-jp", "EUCJ", 'E', B_EUC_CONVERSION}, {"EUC-kr", "EUCK", 'K', B_EUC_KR_CONVERSION}, - + {"GB18030", "GB18030", 'G', B_GBK_CONVERSION}, + {"Big5", "Big5", 'B', B_BIG5_CONVERSION}, /* Not Implemented. {"EUC-tw", "EUCT", "T", M_EUC_TW}, - {"Big5", "Big5", 'B', M_BIG5}, {"ISO-2022-cn", "ISOC", 'C', M_ISO_2022_CN}, {"ISO-2022-kr", "ISOK", 'R', M_ISO_2022_KR}, */ diff --git a/src/apps/terminal/TermParse.cpp b/src/apps/terminal/TermParse.cpp index e7830f0987..f4647429b4 100644 --- a/src/apps/terminal/TermParse.cpp +++ b/src/apps/terminal/TermParse.cpp @@ -326,6 +326,7 @@ TermParse::EscParse() int *groundtable = gUTF8GroundTable; int *parsestate = groundtable; + int width = 1; BAutolock locker(fBuffer); while (!fQuitting) { @@ -358,6 +359,8 @@ TermParse::EscParse() case B_EUC_CONVERSION: case B_EUC_KR_CONVERSION: case B_JIS_CONVERSION: + case B_GBK_CONVERSION: + case B_BIG5_CONVERSION: groundtable = gISO8859GroundTable; break; case M_UTF8: @@ -378,10 +381,14 @@ TermParse::EscParse() case CASE_PRINT_GR: /* case iso8859 gr character, or euc */ ptr = cbuf; - if (now_coding == B_EUC_CONVERSION || now_coding == B_EUC_KR_CONVERSION - || now_coding == B_JIS_CONVERSION) { + if (now_coding == B_EUC_CONVERSION + || now_coding == B_EUC_KR_CONVERSION + || now_coding == B_JIS_CONVERSION + || now_coding == B_GBK_CONVERSION + || now_coding == B_BIG5_CONVERSION) { switch (parsestate[curess]) { case CASE_SS2: /* JIS X 0201 */ + width = 1; *ptr++ = curess; *ptr++ = c; *ptr = 0; @@ -389,6 +396,7 @@ TermParse::EscParse() break; case CASE_SS3: /* JIS X 0212 */ + width = 1; *ptr++ = curess; *ptr++ = c; _NextParseChar(c); @@ -398,6 +406,7 @@ TermParse::EscParse() break; default: /* JIS X 0208 */ + width = 2; *ptr++ = c; _NextParseChar(c); *ptr++ = c; @@ -417,7 +426,7 @@ TermParse::EscParse() B_EUC_CONVERSION); } - fBuffer->InsertChar(dstbuf, 4, attr); + fBuffer->InsertChar(dstbuf, 4, width, attr); break; case CASE_PRINT_CS96: diff --git a/src/apps/terminal/TermView.cpp b/src/apps/terminal/TermView.cpp index dc6b67d0c9..34696a7bfa 100644 --- a/src/apps/terminal/TermView.cpp +++ b/src/apps/terminal/TermView.cpp @@ -1025,6 +1025,9 @@ TermView::Draw(BRect updateRect) continue; } + if (IS_WIDTH(attr)) + count = 2; + _DrawLinePart(fFontWidth * i, (int32)_LineOffset(j), attr, buf, count, insideSelection, false, this); i += count;