Applied patch by h.z. (slightly modified by myself) included in bug #2715. I tested it briefly with Konatu Tohaba font and it seems to work correctly. Please review.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29129 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2009-02-03 14:04:52 +00:00
parent 64f6da317c
commit f498be9297
7 changed files with 69 additions and 13 deletions
+26 -1
View File
@@ -18,9 +18,34 @@
#include <MenuItem.h> #include <MenuItem.h>
#include <PopUpMenu.h> #include <PopUpMenu.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
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, AppearancePrefView::AppearancePrefView(BRect frame, const char *name,
BMessenger messenger) BMessenger messenger)
: PrefView(frame, name), : PrefView(frame, name),
@@ -170,7 +195,7 @@ AppearancePrefView::_MakeFontMenu(uint32 command, const char *defaultFontName)
if (get_font_family(i, &family, &flags) == B_OK) { if (get_font_family(i, &family, &flags) == B_OK) {
BFont font; BFont font;
font.SetFamilyAndStyle(family, NULL); font.SetFamilyAndStyle(family, NULL);
if (font.IsFixed()) { if (IsFontUsable(font)) {
BMenuItem *item = new BMenuItem(family, new BMessage(command)); BMenuItem *item = new BMenuItem(family, new BMessage(command));
menu->AddItem(item); menu->AddItem(item);
if (!strcmp(defaultFontName, family)) if (!strcmp(defaultFontName, family))
+3 -2
View File
@@ -537,11 +537,12 @@ BasicTerminalBuffer::Find(const char* _pattern, const TermPos& start,
void void
BasicTerminalBuffer::InsertChar(UTF8Char c, uint32 attributes) BasicTerminalBuffer::InsertChar(UTF8Char c, uint32 width, uint32 attributes)
{ {
//debug_printf("BasicTerminalBuffer::InsertChar('%.*s' (%d), %#lx)\n", //debug_printf("BasicTerminalBuffer::InsertChar('%.*s' (%d), %#lx)\n",
//(int)c.ByteCount(), c.bytes, c.bytes[0], attributes); //(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) if (width == FULL_WIDTH)
attributes |= A_WIDTH; attributes |= A_WIDTH;
+23 -4
View File
@@ -96,9 +96,14 @@ public:
TermPos& matchEnd) const; TermPos& matchEnd) const;
// insert chars/lines // insert chars/lines
void InsertChar(UTF8Char c, uint32 attributes); inline void InsertChar(UTF8Char c, uint32 attributes);
inline void InsertChar(const char* c, int32 length, void InsertChar(UTF8Char c, uint32 width,
uint32 attributes); 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 InsertCR();
void InsertLF(); void InsertLF();
void SetInsertMode(int flag); void SetInsertMode(int flag);
@@ -209,10 +214,24 @@ BasicTerminalBuffer::HistoryCapacity() const
} }
void
BasicTerminalBuffer::InsertChar(UTF8Char c, uint32 attributes)
{
return InsertChar(c, 1, attributes);
}
void void
BasicTerminalBuffer::InsertChar(const char* c, int32 length, uint32 attributes) 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);
} }
-1
View File
@@ -38,7 +38,6 @@ extern char gUTF8WidthTable[]; // defined in UTF8WidthTbl.c
int32 int32
CodeConv::UTF8GetFontWidth(const char *string) CodeConv::UTF8GetFontWidth(const char *string)
{ {
return 1;
ushort unicode = UTF8toUnicode(string); ushort unicode = UTF8toUnicode(string);
uchar width = gUTF8WidthTable[unicode >> 3]; uchar width = gUTF8WidthTable[unicode >> 3];
ushort offset = unicode & 0x07; ushort offset = unicode & 0x07;
+2 -2
View File
@@ -30,11 +30,11 @@ const static etable kEncodingTable[] =
{"Shift-JIS", "SJIS", 'S', B_SJIS_CONVERSION}, {"Shift-JIS", "SJIS", 'S', B_SJIS_CONVERSION},
{"EUC-jp", "EUCJ", 'E', B_EUC_CONVERSION}, {"EUC-jp", "EUCJ", 'E', B_EUC_CONVERSION},
{"EUC-kr", "EUCK", 'K', B_EUC_KR_CONVERSION}, {"EUC-kr", "EUCK", 'K', B_EUC_KR_CONVERSION},
{"GB18030", "GB18030", 'G', B_GBK_CONVERSION},
{"Big5", "Big5", 'B', B_BIG5_CONVERSION},
/* Not Implemented. /* Not Implemented.
{"EUC-tw", "EUCT", "T", M_EUC_TW}, {"EUC-tw", "EUCT", "T", M_EUC_TW},
{"Big5", "Big5", 'B', M_BIG5},
{"ISO-2022-cn", "ISOC", 'C', M_ISO_2022_CN}, {"ISO-2022-cn", "ISOC", 'C', M_ISO_2022_CN},
{"ISO-2022-kr", "ISOK", 'R', M_ISO_2022_KR}, {"ISO-2022-kr", "ISOK", 'R', M_ISO_2022_KR},
*/ */
+12 -3
View File
@@ -326,6 +326,7 @@ TermParse::EscParse()
int *groundtable = gUTF8GroundTable; int *groundtable = gUTF8GroundTable;
int *parsestate = groundtable; int *parsestate = groundtable;
int width = 1;
BAutolock locker(fBuffer); BAutolock locker(fBuffer);
while (!fQuitting) { while (!fQuitting) {
@@ -358,6 +359,8 @@ TermParse::EscParse()
case B_EUC_CONVERSION: case B_EUC_CONVERSION:
case B_EUC_KR_CONVERSION: case B_EUC_KR_CONVERSION:
case B_JIS_CONVERSION: case B_JIS_CONVERSION:
case B_GBK_CONVERSION:
case B_BIG5_CONVERSION:
groundtable = gISO8859GroundTable; groundtable = gISO8859GroundTable;
break; break;
case M_UTF8: case M_UTF8:
@@ -378,10 +381,14 @@ TermParse::EscParse()
case CASE_PRINT_GR: case CASE_PRINT_GR:
/* case iso8859 gr character, or euc */ /* case iso8859 gr character, or euc */
ptr = cbuf; ptr = cbuf;
if (now_coding == B_EUC_CONVERSION || now_coding == B_EUC_KR_CONVERSION if (now_coding == B_EUC_CONVERSION
|| now_coding == B_JIS_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]) { switch (parsestate[curess]) {
case CASE_SS2: /* JIS X 0201 */ case CASE_SS2: /* JIS X 0201 */
width = 1;
*ptr++ = curess; *ptr++ = curess;
*ptr++ = c; *ptr++ = c;
*ptr = 0; *ptr = 0;
@@ -389,6 +396,7 @@ TermParse::EscParse()
break; break;
case CASE_SS3: /* JIS X 0212 */ case CASE_SS3: /* JIS X 0212 */
width = 1;
*ptr++ = curess; *ptr++ = curess;
*ptr++ = c; *ptr++ = c;
_NextParseChar(c); _NextParseChar(c);
@@ -398,6 +406,7 @@ TermParse::EscParse()
break; break;
default: /* JIS X 0208 */ default: /* JIS X 0208 */
width = 2;
*ptr++ = c; *ptr++ = c;
_NextParseChar(c); _NextParseChar(c);
*ptr++ = c; *ptr++ = c;
@@ -417,7 +426,7 @@ TermParse::EscParse()
B_EUC_CONVERSION); B_EUC_CONVERSION);
} }
fBuffer->InsertChar(dstbuf, 4, attr); fBuffer->InsertChar(dstbuf, 4, width, attr);
break; break;
case CASE_PRINT_CS96: case CASE_PRINT_CS96:
+3
View File
@@ -1025,6 +1025,9 @@ TermView::Draw(BRect updateRect)
continue; continue;
} }
if (IS_WIDTH(attr))
count = 2;
_DrawLinePart(fFontWidth * i, (int32)_LineOffset(j), _DrawLinePart(fFontWidth * i, (int32)_LineOffset(j),
attr, buf, count, insideSelection, false, this); attr, buf, count, insideSelection, false, this);
i += count; i += count;