* Fixed broken CodeConv semantics (missing length parameter).
* No longer writes to the message data from clipboard. * some cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15153 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
498cd44c3a
commit
8eb8269db6
@ -1,34 +1,11 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2005, Haiku, Inc.
|
||||
* Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
|
||||
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files or portions
|
||||
* thereof (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so, subject
|
||||
* to the following conditions:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice
|
||||
* in the binary, as well as this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided with
|
||||
* the distribution.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* Distributed under the terms of the MIT license.
|
||||
*/
|
||||
|
||||
/************************************************************************
|
||||
/*********************************************************************
|
||||
MuTerminal Code Conversion class (MC3).
|
||||
|
||||
version 1.1 Internal coding system is UTF8.
|
||||
@ -52,89 +29,86 @@ UTF8
|
||||
|
||||
extern char utf8_width_table[]; /* define UTF8WidthTbl.c */
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
CodeConv::CodeConv (void)
|
||||
{
|
||||
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Destructor
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
CodeConv::~CodeConv (void)
|
||||
CodeConv::CodeConv()
|
||||
{
|
||||
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// UTF8GetFontWidth (const uchar *string)
|
||||
// get font width in coding.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
int
|
||||
CodeConv::UTF8GetFontWidth (const uchar *string)
|
||||
{
|
||||
uchar width, point;
|
||||
ushort unicode, offset;
|
||||
|
||||
offset = unicode = UTF8toUnicode (string);
|
||||
width = utf8_width_table [unicode >> 3];
|
||||
offset = offset & 0x07;
|
||||
|
||||
point = 0x80 >> offset;
|
||||
|
||||
return ((width & point) > 0 ) ? 2 : 1;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// ConvertFromInternal (const uchar *src, uchar *dst, int coding)
|
||||
// Convert internal coding from src coding.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
int
|
||||
CodeConv::ConvertFromInternal (const uchar *src, uchar *dst, int coding)
|
||||
|
||||
CodeConv::~CodeConv()
|
||||
{
|
||||
const uchar *src_p = src;
|
||||
long srclen = 0, dstlen = 0;
|
||||
long state = 0;
|
||||
int theCoding;
|
||||
|
||||
if (coding == M_UTF8) return 0;
|
||||
|
||||
theCoding = coding_translation_table[coding];
|
||||
|
||||
while (*src_p++) srclen++;
|
||||
|
||||
dstlen = srclen * 256;
|
||||
|
||||
convert_from_utf8 (theCoding,
|
||||
(char *)src, &srclen,
|
||||
(char *)dst, &dstlen,
|
||||
&state, '?');
|
||||
|
||||
if (coding == M_ISO_2022_JP && state != 0) {
|
||||
const char *end_of_jis = "(B";
|
||||
strncpy ((char *)dst+dstlen, end_of_jis, 3);
|
||||
dstlen += 3;
|
||||
}
|
||||
|
||||
dst[dstlen] = '\0';
|
||||
|
||||
return dstlen;
|
||||
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// ConvertToInternal (const uchar *src, uchar *dst, int coding)
|
||||
// Convert internal coding to src coding.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
CodeConv::ConvertToInternal (const uchar *src, uchar *dst, int coding)
|
||||
{
|
||||
const uchar *src_p = src;
|
||||
long srclen = 0, dstlen = 4;
|
||||
long state = 0;
|
||||
int theCoding;
|
||||
|
||||
|
||||
if (coding == M_UTF8) return;
|
||||
|
||||
//! get font width in coding.
|
||||
int32
|
||||
CodeConv::UTF8GetFontWidth(const char *string)
|
||||
{
|
||||
uchar width, point;
|
||||
ushort unicode, offset;
|
||||
|
||||
offset = unicode = UTF8toUnicode(string);
|
||||
width = utf8_width_table[unicode >> 3];
|
||||
offset = offset & 0x07;
|
||||
|
||||
point = 0x80 >> offset;
|
||||
|
||||
return (width & point) > 0 ? 2 : 1;
|
||||
}
|
||||
|
||||
|
||||
//! Convert internal coding from src coding.
|
||||
int32
|
||||
CodeConv::ConvertFromInternal(const char *src, int32 srclen, char *dst, int coding)
|
||||
{
|
||||
int32 dstlen = 0;
|
||||
long state = 0;
|
||||
int theCoding;
|
||||
|
||||
if (srclen == -1)
|
||||
srclen = strlen(src);
|
||||
|
||||
if (coding == M_UTF8) {
|
||||
memcpy(dst, src, srclen);
|
||||
dst[srclen] = '\0';
|
||||
return srclen;
|
||||
}
|
||||
|
||||
theCoding = coding_translation_table[coding];
|
||||
|
||||
|
||||
dstlen = srclen * 256;
|
||||
|
||||
convert_from_utf8(theCoding, (char *)src, &srclen,
|
||||
(char *)dst, &dstlen, &state, '?');
|
||||
|
||||
if (coding == M_ISO_2022_JP && state != 0) {
|
||||
const char *end_of_jis = "(B";
|
||||
strncpy((char *)dst + dstlen, end_of_jis, 3);
|
||||
dstlen += 3;
|
||||
}
|
||||
|
||||
dst[dstlen] = '\0';
|
||||
return dstlen;
|
||||
}
|
||||
|
||||
|
||||
//! Convert internal coding to src coding.
|
||||
int32
|
||||
CodeConv::ConvertToInternal(const char *src, int32 srclen, char *dst, int coding)
|
||||
{
|
||||
int32 dstlen = 4;
|
||||
long state = 0;
|
||||
int theCoding;
|
||||
|
||||
if (srclen == -1)
|
||||
srclen = strlen(src);
|
||||
|
||||
if (coding == M_UTF8) {
|
||||
memcpy(dst, src, srclen);
|
||||
dst[srclen] = '\0';
|
||||
return srclen;
|
||||
}
|
||||
|
||||
#if 0
|
||||
#ifndef __INTEL__
|
||||
@ -149,96 +123,72 @@ CodeConv::ConvertToInternal (const uchar *src, uchar *dst, int coding)
|
||||
dst[dstlen] = '\0';
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
theCoding = coding_translation_table[coding];
|
||||
|
||||
while (*src_p++) srclen++;
|
||||
|
||||
convert_to_utf8 (theCoding,
|
||||
(char *)src, &srclen,
|
||||
(char *)dst, &dstlen,
|
||||
&state, '?');
|
||||
theCoding = coding_translation_table[coding];
|
||||
|
||||
dst[dstlen] = '\0';
|
||||
convert_to_utf8(theCoding, (char *)src, &srclen,
|
||||
(char *)dst, &dstlen, &state, '?');
|
||||
|
||||
return;
|
||||
dst[dstlen] = '\0';
|
||||
return dstlen;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Private member functions.
|
||||
*/
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// UTF8toUnicode (uchar *utf8)
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
unsigned short
|
||||
CodeConv::UTF8toUnicode (const uchar *utf8)
|
||||
CodeConv::UTF8toUnicode(const char *utf8)
|
||||
{
|
||||
uchar tmp;
|
||||
unsigned short unicode = 0x0000;
|
||||
|
||||
tmp = *utf8 & 0xe0;
|
||||
|
||||
if (tmp < 0x80) {
|
||||
unicode = (unsigned short) *utf8;
|
||||
}
|
||||
else if (tmp < 0xe0) {
|
||||
unicode = (unsigned short) *utf8++ & 0x1f;
|
||||
unicode = unicode << 6;
|
||||
unicode = unicode | ((unsigned short) *utf8 & 0x3f);
|
||||
}
|
||||
else if (tmp < 0xf0) {
|
||||
unicode = (unsigned short) *utf8++ & 0x0f;
|
||||
unicode = unicode << 6;
|
||||
unicode = unicode | ((unsigned short) *utf8++ & 0x3f);
|
||||
unicode = unicode << 6;
|
||||
unicode = unicode | ((unsigned short) *utf8 & 0x3f);
|
||||
}
|
||||
uchar tmp;
|
||||
unsigned short unicode = 0x0000;
|
||||
|
||||
return unicode;
|
||||
tmp = *utf8 & 0xe0;
|
||||
|
||||
if (tmp < 0x80) {
|
||||
unicode = (unsigned short)*utf8;
|
||||
} else if (tmp < 0xe0) {
|
||||
unicode = (unsigned short)*utf8++ & 0x1f;
|
||||
unicode = unicode << 6;
|
||||
unicode = unicode | ((unsigned short)*utf8 & 0x3f);
|
||||
} else if (tmp < 0xf0) {
|
||||
unicode = (unsigned short)*utf8++ & 0x0f;
|
||||
unicode = unicode << 6;
|
||||
unicode = unicode | ((unsigned short)*utf8++ & 0x3f);
|
||||
unicode = unicode << 6;
|
||||
unicode = unicode | ((unsigned short)*utf8 & 0x3f);
|
||||
}
|
||||
|
||||
return unicode;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// euc_to_sjis
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
void
|
||||
CodeConv::euc_to_sjis (uchar *buf)
|
||||
CodeConv::euc_to_sjis(uchar *buf)
|
||||
{
|
||||
int gl, gr;
|
||||
int p;
|
||||
int c1, c2;
|
||||
|
||||
gl = *buf & 0x7F;
|
||||
gr = *(buf + 1) & 0x7F;
|
||||
gl -= 0x21;
|
||||
gr -= 0x21;
|
||||
int gl, gr;
|
||||
int p;
|
||||
int c1, c2;
|
||||
|
||||
p = gl * 94 + gr;
|
||||
|
||||
c1 = p / 188;
|
||||
c2 = p % 188;
|
||||
|
||||
if (c1 >= 31) {
|
||||
c1 = c1 - 31 + 0xE0;
|
||||
}
|
||||
else {
|
||||
c1 += 0x81;
|
||||
}
|
||||
|
||||
if (c2 >= 63) {
|
||||
c2 = c2 - 63 + 0x80;
|
||||
}
|
||||
else {
|
||||
c2 += 0x40;
|
||||
}
|
||||
|
||||
*buf++ = c1;
|
||||
*buf = c2;
|
||||
gl = *buf & 0x7F;
|
||||
gr = *(buf + 1) & 0x7F;
|
||||
gl -= 0x21;
|
||||
gr -= 0x21;
|
||||
|
||||
return;
|
||||
p = gl * 94 + gr;
|
||||
|
||||
c1 = p / 188;
|
||||
c2 = p % 188;
|
||||
|
||||
if (c1 >= 31)
|
||||
c1 = c1 - 31 + 0xE0;
|
||||
else
|
||||
c1 += 0x81;
|
||||
|
||||
if (c2 >= 63)
|
||||
c2 = c2 - 63 + 0x80;
|
||||
else
|
||||
c2 += 0x40;
|
||||
|
||||
*buf++ = c1;
|
||||
*buf = c2;
|
||||
}
|
||||
|
@ -1,83 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2005, Haiku, Inc.
|
||||
* Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
|
||||
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files or portions
|
||||
* thereof (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so, subject
|
||||
* to the following conditions:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice
|
||||
* in the binary, as well as this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided with
|
||||
* the distribution.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* Distributed under the terms of the MIT license.
|
||||
*/
|
||||
|
||||
#ifndef CODECONV_H
|
||||
#define CODECONV_H
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
#include "Coding.h"
|
||||
|
||||
#define BEGINS_CHAR(byte) ((byte & 0xc0) >= 0x80)
|
||||
|
||||
/*
|
||||
* Coding system define.
|
||||
*/
|
||||
class CodeConv
|
||||
{
|
||||
/*
|
||||
* Constructor and Destuructor.
|
||||
*/
|
||||
public:
|
||||
CodeConv (void);
|
||||
~CodeConv (void);
|
||||
|
||||
/*
|
||||
* Public member functions.
|
||||
*/
|
||||
int UTF8GetFontWidth (const uchar *string);
|
||||
class CodeConv {
|
||||
public:
|
||||
CodeConv();
|
||||
~CodeConv();
|
||||
|
||||
/* internal(UTF8) -> coding */
|
||||
int ConvertFromInternal (const uchar *src, uchar *dst, int coding);
|
||||
int32 UTF8GetFontWidth(const char *string);
|
||||
|
||||
/* coding -> internal(UTF8) */
|
||||
void ConvertToInternal (const uchar *src, uchar *dst, int coding);
|
||||
|
||||
/*
|
||||
* PRIVATE MEMBER.
|
||||
*/
|
||||
/* internal(UTF8) -> coding */
|
||||
int32 ConvertFromInternal(const char *src, int32 bytes, char *dst, int coding);
|
||||
|
||||
private:
|
||||
/*
|
||||
* Private member functions.
|
||||
*/
|
||||
/* coding -> internal(UTF8) */
|
||||
int32 ConvertToInternal(const char *src, int32 bytes, char *dst, int coding);
|
||||
|
||||
void euc_to_sjis (uchar *buf);
|
||||
private:
|
||||
void euc_to_sjis(uchar *buf);
|
||||
|
||||
unsigned short UTF8toUnicode (const uchar *utf8);
|
||||
unsigned short UTF8toUnicode(const char *utf8);
|
||||
|
||||
/*
|
||||
* DATA Member.
|
||||
*/
|
||||
|
||||
int fNowCoding;
|
||||
|
||||
int fNowCoding;
|
||||
};
|
||||
|
||||
#endif /* CODECONV_H */
|
||||
|
@ -3,34 +3,42 @@
|
||||
* Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
|
||||
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
* Authors:
|
||||
* Kian Duffy <myob@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
/*! This view is a shell for the TermView and makes sure it's always
|
||||
resized in whole character sizes.
|
||||
It doesn't serve any other purpose (and could possibly removed
|
||||
with a tiny bit smarter programming).
|
||||
*/
|
||||
|
||||
|
||||
#include "TermBaseView.h"
|
||||
#include "TermView.h"
|
||||
|
||||
TermBaseView::TermBaseView (BRect frame, TermView *inTermView)
|
||||
:BView(frame, "baseview", B_FOLLOW_ALL_SIDES,
|
||||
|
||||
TermBaseView::TermBaseView(BRect frame, TermView *inTermView)
|
||||
: BView(frame, "baseview", B_FOLLOW_ALL_SIDES,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS)
|
||||
{
|
||||
fTermView = inTermView;
|
||||
}
|
||||
|
||||
TermBaseView::~TermBaseView ()
|
||||
|
||||
TermBaseView::~TermBaseView()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TermBaseView::FrameResized (float width, float height)
|
||||
TermBaseView::FrameResized(float width, float height)
|
||||
{
|
||||
int font_width, font_height;
|
||||
int fontWidth, fontHeight;
|
||||
int cols, rows;
|
||||
|
||||
fTermView->GetFontInfo (&font_width, &font_height);
|
||||
|
||||
cols = (int)(width - VIEW_OFFSET * 2) / font_width;
|
||||
rows = (int)(height - VIEW_OFFSET * 2)/ font_height;
|
||||
|
||||
fTermView->ResizeTo (cols * font_width - 1, rows * font_height - 1);
|
||||
|
||||
fTermView->GetFontInfo(&fontWidth, &fontHeight);
|
||||
|
||||
cols = (int)(width - VIEW_OFFSET * 2) / fontWidth;
|
||||
rows = (int)(height - VIEW_OFFSET * 2) / fontHeight;
|
||||
|
||||
fTermView->ResizeTo(cols * fontWidth - 1, rows * fontHeight - 1);
|
||||
}
|
||||
|
@ -1,58 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2005, Haiku, Inc.
|
||||
* Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
|
||||
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files or portions
|
||||
* thereof (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so, subject
|
||||
* to the following conditions:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice
|
||||
* in the binary, as well as this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided with
|
||||
* the distribution.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* Distributed under the terms of the MIT license.
|
||||
*/
|
||||
#ifndef TERM_BASE_VIEW_H
|
||||
#define TERM_BASE_VIEW_H
|
||||
|
||||
|
||||
#ifndef TERMBASEVIEW_H_INCLUDED
|
||||
#define TERMBASEVIEW_H_INCLUDED
|
||||
#include <View.h>
|
||||
|
||||
|
||||
class TermView;
|
||||
|
||||
class TermBaseView : public BView
|
||||
{
|
||||
public:
|
||||
//
|
||||
// Constructor and Desctructor
|
||||
//
|
||||
TermBaseView (BRect frame, TermView *);
|
||||
~TermBaseView ();
|
||||
|
||||
private:
|
||||
//
|
||||
// Hook Functions.
|
||||
//
|
||||
void SetBaseColor (rgb_color);
|
||||
|
||||
void FrameResized (float, float);
|
||||
class TermBaseView : public BView {
|
||||
public:
|
||||
TermBaseView(BRect frame, TermView *);
|
||||
~TermBaseView();
|
||||
|
||||
TermView *fTermView;
|
||||
|
||||
private:
|
||||
void SetBaseColor(rgb_color);
|
||||
virtual void FrameResized(float newWidth, float newHeight);
|
||||
|
||||
TermView *fTermView;
|
||||
};
|
||||
|
||||
#endif /* TERMBASEVIEW_H_INCLUDED */
|
||||
#endif /* TERM_BASE_VIEW_H */
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user