home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOKAN 17
/
DOKAN17.iso
/
Progs
/
Pjv03dde.zip
/
PJV03DDE
/
SRCCODE
/
MAIN
/
NIHONGO.PAS
Wrap
Pascal/Delphi Source File
|
1999-08-29
|
21KB
|
641 lines
//
// NIHONGO ENGINE v0.3d for Delphi 2.0+ [29/08/99]
// (c)1999 Pulsar Studio, all rights reserved.
// Freeware. Developed by Lord Trancos.
//
// This is a recopilation and adaptation of some routines
// that I created in 97 for Turbo Pascal.
//
// Please, distribute the source code without any modification.
//
// Greetings to Dark Shadow, R⌠nin, Multidimensional Careto,
// Takuya, Kanjiman, FidoNet r34.Japones, FIC BBS,
// DOKAN and ONELIST.COM MLJ (Mail List Japones)
//
{$A-}
unit NIHONGO;
// --------------------------------------------------------------------
INTERFACE
uses Windows, SysUtils;
const jJAPFNT = 'JVIEWER.JAP'; // Japanese Characters File Name
jASCFNT = 'JVIEWER.ASC'; // Ascii Characters File Name
// Main Functions
function jInitialize: boolean;
procedure jClose;
function jWriteSJS(_x, _y: integer; _dstW, _dstH: word;
_text: string; _vert, _xor: boolean;
_hdc: HDC): boolean;
function jWriteEUC(_x, _y: integer; _dstW, _dstH: word;
_text: string; _vert, _xor: boolean;
_hdc: HDC): boolean;
function jEUC2SJS(_str: string): string; // jInitialize not requiered.
function jBreakSJS(_text: string; _length: word): string; // jInitialize not requiered.
// Aditional Functions - jInitialize requiered
function aDrawChar(_x, _y: integer; _dstW, _dstH: word;
_chr: word; _xor: boolean; _hdc: HDC): boolean;
function jDrawChar(_x, _y: integer; _dstW, _dstH: word;
_chr: word; _xor: boolean; _hdc: HDC): boolean;
function jChooseChar(_w: word): word;
// More Aditional Functions - jInitialize not requiered
function jOpenBinFile(_fn: string; var _f: file): boolean;
function jLoadFile(_src: string; _dest: pointer): boolean;
// --------------------------------------------------------------------
IMPLEMENTATION
type jCHAR = array[0..31] of byte; // Japanese Character Data
// 16x16 pixels (1 bpp)
aCHAR = array[0..15] of byte; // Ascii Character Data
// 8x16 pixels (1 bpp)
const NUMCHARS = 6877; // Total Japanese Characters
NUMASC = 256; // Total Ascii Characters
// Don't modify
POS00 = 6524;
POS01 = 2;
POS02 = 6187;
POS03 = 4683;
POS04 = 3179;
POS05 = 1675;
POS06 = 171;
BRK00 = #32;
BRK01 = #47;
var jCHARS : array[1..NUMCHARS] of jCHAR; // jFont in Memory
aCHARS : array[1..NUMASC] of aCHAR; // aFont in Memory
jPIC : HBITMAP; // Bitmap used to Draw
jASC : HBITMAP; // Bitmap used to Draw
JPICDC : HDC; // DC used to Draw
jASCDC : HDC; // DC used to Draw
jKANJIS : array[1..32] of byte; // Don't modify
// --------------------------------------------------------------------
function jOpenBinFile(_fn: string; var _f: file): boolean;
begin
Assign(_f, _fn);
{$I-}
FileMode := 0;
Reset(_f, 1);
{$I+}
if (IOResult <> 0) and (_fn <> '') then
jOpenBinFile := false else jOpenBinFile := true;
end;
// --------------------------------------------------------------------
function jLoadFile(_src: string; _dest: pointer): boolean;
var _f : file;
_s : longint;
_r : boolean;
begin
_r := false;
if jOpenBinFile(_src, _f) = true then
begin
_s := FileSize(_f);
{$I-}
BlockRead(_f, _dest^, _s);
{$I+}
if (IOResult = 0) then _r := true;
CloseFile(_f);
end;
jLoadFile := _r;
end;
// --------------------------------------------------------------------
function jHispaFilter(_chr: word): word;
// support for windows spanish chars
var _r: word;
begin
_r := pred(_chr);
case _r of
$D1: _r := $A5; // ╤
$F1: _r := $A4; // ±
$E1: _r := $A0; // ß
$E9: _r := $82; // Θ
$ED: _r := $A1; // φ
$F3: _r := $A2; // ≤
$FA: _r := $A3; // ·
$C1: _r := $A0; // ┴
$C9: _r := $82; // ═
$CD: _r := $A1; // ┌
$D3: _r := $A2; // ╔
$DA: _r := $A3; // ╙
end;
inc(_r);
jHispaFilter := _r;
end;
// --------------------------------------------------------------------
{
procedure jDoubleSpaceFilter(var _str: string);
// change 'ü@' with ' '
var _cnt : byte;
begin
if length(_str) < 2 then exit;
for _cnt := 1 to length(_str)-1 do
if (byte(_str[_cnt]) = 129) and (byte(_str[_cnt+1]) = 64)
then begin _str[_cnt] := ' '; _str[_cnt+1] := ' '; end;
end;
}
// --------------------------------------------------------------------
function aDrawChar(_x, _y: integer; _dstW, _dstH: word;
_chr: word; _xor: boolean; _hdc: HDC): boolean;
{
_x, _y - destination into the window
_dstW, _dstH - destination size (must be 8x16 or more.
recomended sizes: 8x16, 16x32, ..)
_chr - ascii character #
_xor - invert character
_hdc - destination HDC
}
var{_src : HDC;}
_jChr : jCHAR;
_cnt : byte;
begin
aDrawChar := false;
// Check selected character and size
if (_chr = 0) or (_chr > NUMASC) then exit;
if (_dstW < 8) or (_dstH < 16) then exit; // Lower size is stupid!
// Select DC
{ _src := CreateCompatibleDC(_hdc);
if _src = NULL then exit; }
{ if SelectObject(jASCDC, jASC) = NULL then exit; }
// Draw into the Bitmap
if _xor = false then
for _cnt := 0 to 15 do _jChr[_cnt shl 1] := aCHARS[_chr][_cnt]
else for _cnt := 0 to 15 do _jChr[_cnt shl 1] := not aCHARS[_chr][_cnt];
if SetBitmapBits(jASC, sizeof(jCHAR), @_jChr) = 0 then exit;
// Draw Bitmap
if (_dstW = 8) and (_dstH = 16) then
begin
if BitBlt(_hdc, _x, _y, 8, 16, jASCDC, 0, 0,
SRCCOPY) = false then exit;
end else
if StretchBlt(_hdc, _x, _y, _dstW, _dstH, jASCDC, 0, 0,
8, 16, SRCCOPY) = false then exit;
{
// Release and Delete DCs
if DeleteDC(_src) = false then exit;
}
// all ok!
aDrawChar := true;
end;
// --------------------------------------------------------------------
function jDrawChar(_x, _y: integer; _dstW, _dstH: word;
_chr: word; _xor: boolean; _hdc: HDC): boolean;
{
_x, _y - destination into the window
_dstW, _dstH - destination size (must be 16 or more.
recomended sizes: 16, 32, 64...)
_chr - japanese character #
_xor - invert character
_hdc - destination HDC
}
var{_src : HDC;}
_jChr : jCHAR;
_cnt : byte;
begin
jDrawChar := false;
// Check selected character and size
if (_chr = 0) or (_chr > NUMCHARS) then exit;
if (_dstW < 16) or (_dstH < 16) then exit; // Lower size is stupid!
// Select DC
{ _src := CreateCompatibleDC(_hdc);
if _src = NULL then exit; }
{ if SelectObject(jPICDC, jPIC) = NULL then exit; }
// Draw into the Bitmap
if _xor = false then
begin
for _cnt := 0 to 15 do
begin
_jChr[(_cnt shl 1)] := jCHARS[_chr][_cnt];
_jChr[(_cnt shl 1) + 1] := jCHARS[_chr][_cnt + 16];
end;
end else
begin
for _cnt := 0 to 15 do
begin
_jChr[(_cnt shl 1)] := not jCHARS[_chr][_cnt];
_jChr[(_cnt shl 1) + 1] := not jCHARS[_chr][_cnt + 16];
end;
end;
if SetBitmapBits(jPIC, sizeof(jCHAR), @_jChr) = 0 then exit;
// Draw Bitmap
if (_dstW = 16) and (_dstH = 16) then
begin
if BitBlt(_hdc, _x, _y, 16, 16, jPICDC, 0, 0,
SRCCOPY) = false then exit;
end else
if StretchBlt(_hdc, _x, _y, _dstW, _dstH, jPICDC, 0, 0,
16, 16, SRCCOPY) = false then exit;
{
// Release and Delete DCs
if DeleteDC(_src) = false then exit;
}
// all ok!
jDrawChar := true;
end;
// --------------------------------------------------------------------
function jEUC2SJS(_str: string): string;
var _cnt: byte;
_res: String;
Begin
_res := _str;
if length(_str)>0 then
begin
_cnt := 0;
repeat
inc(_cnt);
if (byte(_res[_cnt])>126) and (length(_str)>1) then
case byte(_res[_cnt]) of
164: if (byte(_res[_cnt+1])>160) and (byte(_res[_cnt+1])<244) then
begin { Hiragana }
byte(_res[_cnt]) := 130;
inc(_cnt);
dec(byte(_res[_cnt]), 2);
end;
165: if (byte(_res[_cnt+1])>160) and (byte(_res[_cnt+1])<247) then
begin { Katagana }
byte(_res[_cnt]) := 131;
inc(_cnt);
if byte(_res[_cnt])<224 then dec(byte(_res[_cnt]), 97)
else dec(byte(_res[_cnt]), 96);
end;
163: begin { Lat }
byte(_res[_cnt]) := 130;
inc(_cnt);
if byte(_res[_cnt])<224 then dec(byte(_res[_cnt]), 97)
else dec(byte(_res[_cnt]), 96);
end;
166: begin { Grc }
byte(_res[_cnt]) := 131;
inc(_cnt);
dec(byte(_res[_cnt]), 2);
end;
167: begin { Rus }
byte(_res[_cnt]) := 132;
inc(_cnt);
if byte(_res[_cnt])<224 then dec(byte(_res[_cnt]), 97)
else dec(byte(_res[_cnt]), 96);
end;
168: begin { Lin }
byte(_res[_cnt]) := 132;
inc(_cnt);
dec(byte(_res[_cnt]), 2);
end;
161: begin { Misc 1 }
byte(_res[_cnt]) := 129;
inc(_cnt);
if byte(_res[_cnt])<224 then dec(byte(_res[_cnt]), 97)
else dec(byte(_res[_cnt]), 96);
end;
162: begin { Misc 2 }
byte(_res[_cnt]) := 129;
inc(_cnt);
dec(byte(_res[_cnt]), 2);
end;
else if ((byte(_res[_cnt])>175) and (byte(_res[_cnt])<223)) or
((byte(_res[_cnt])>222) and (byte(_res[_cnt])<245)) then
begin
if byte(_res[_cnt]) and $01 = $00 then
begin
if ((byte(_res[_cnt])>175) and (byte(_res[_cnt])<223)) then
byte(_res[_cnt]):=(136+((byte(_res[_cnt])-176) div 2)) else
byte(_res[_cnt]):=(224+((byte(_res[_cnt])-224) div 2));
inc(_cnt);
dec(byte(_res[_cnt]), 2);
end else
begin
if ((byte(_res[_cnt])>175) and (byte(_res[_cnt])<223)) then
byte(_res[_cnt]):=(137+((byte(_res[_cnt])-177) div 2)) else
byte(_res[_cnt]):=(224+((byte(_res[_cnt])-223) div 2));
inc(_cnt);
if byte(_res[_cnt])<224 then dec(byte(_res[_cnt]), 97)
else dec(byte(_res[_cnt]), 96);
end;
end;
end;
until _cnt >= length(_res);
end;
jEUC2SJS := _res;
end;
// --------------------------------------------------------------------
function jChooseChar(_w: word): word;
// _w - SJS value
var _from : word;
_plus : word;
_b : byte;
_c : array[1..2] of byte;
_d, _z : longint;
begin
_from := 0;
_plus := 0;
_c[1] := _w shr 8;
_c[2] := _w and $FF;
Case _c[1] of
129: if _c[2] = 64 then
begin
_from := 1;
_plus := 0;
end else
begin
_from := POS00 + 208;
if (_c[2]>64) and (_c[2]<173) and (_c[2]<>127) then
if (_c[2]<127)
then _plus := _c[2] - 65
else _plus := _c[2] - 66;
if (_c[2]>183) and (_c[2]<192) then _plus := _c[2] - 77;
if (_c[2]>199) and (_c[2]<207) then _plus := _c[2] - 85;
if (_c[2]>217) and (_c[2]<233) then _plus := _c[2] - 96;
if (_c[2]>239) and (_c[2]<248) then _plus := _c[2] - 103;
if (_c[2]=252) then _plus := _c[2] - 107;
end;
130: if (_c[2]>158) and (_c[2]<242) then
begin
_from := POS01;
_plus := _c[2] - 159;
end else
begin
_from := POS00;
if (_c[2]>78) and (_c[2]<89) then _plus := _c[2] - 79;
if (_c[2]>95) and (_c[2]<122) then _plus := _c[2] - 86;
if (_c[2]>128) and (_c[2]<155) then _plus := _c[2] - 93;
end;
131: if (_c[2]>63) and (_c[2]<151) and (_c[2]<>127) then
begin
_from := POS01 + 83;
if _c[2] < 127
then _plus := _c[2] - 64
else _plus := _c[2] - 65;
end else
begin
_from := POS00 + 62;
if (_c[2]>158) and (_c[2]<183) then _plus := _c[2] - 159;
if (_c[2]>190) and (_c[2]<215) then _plus := _c[2] - 167;
end;
132: begin
_from := POS00 + 110;
if (_c[2]>63) and (_c[2]<97) then _plus := _c[2] - 64;
if (_c[2]>111) and (_c[2]<146) and (_c[2]<>127) then
if _c[2] < 127
then _plus := _c[2] - 79
else _plus := _c[2] - 80;
if (_c[2]>158) and (_c[2]<191) then _plus := _c[2] - 93
end;
136: if (_c[2]>158) and (_c[2]<253) then
begin
_from := POS02;
_plus := _c[2] - 159;
end;
152: begin
_from := POS02 + 94;
if (_c[2]>63) and (_c[2]<115) then _plus := _c[2] - 64;
if (_c[2]>158) and (_c[2]<253) then _plus := _c[2] - 108;
end;
234: if (_c[2]>63) and (_c[2]<163) and (_c[2]<>127) then
begin
_from:= POS02 + 239;
if (_c[2]<127)
then _plus := _c[2] - 64
else _plus := _c[2] -65;
end;
else if ((_c[1]>136) and (_c[1]<152)) or
((_c[1]>152) and (_c[1]<160)) or
((_c[1]>223) and (_c[1]<234)) then
begin
if (_c[2]>63) and (_c[2]<>127) and (_c[2]<253) then
begin
for _b := 1 to 32 do
if _c[1] = jKANJIS[_b] then
begin
case (_b - 1) shr 3 of
0: _from := POS06;
1: _from := POS05;
2: _from := POS04;
3: _from := POS03;
end;
_d := ((_b - (((_b - 1) shr 3) shl 3)) - 1);
inc(_from, longint(_d * 188));
end;
if _c[2] < 127
then _plus := _c[2] - 64
else _plus := _c[2] - 65;
end;
end;
end;
jChooseChar := _from + _plus;
end;
// --------------------------------------------------------------------
function jWriteSJS(_x, _y: integer; _dstW, _dstH: word;
_text: string; _vert, _xor: boolean;
_hdc: HDC): boolean;
var _cnt : byte;
_id : word;
_r : boolean;
_chr : word;
begin
{ jDoubleSpaceFilter(_text); }
_r := true;
_cnt := 1;
if length(_text) > 0 then
repeat
if (_cnt <= length(_text)) then
begin
if _cnt = length(_text) then _id := 0
else _id := jChooseChar((byte(_text[_cnt]) shl 8)
+ byte(_text[_cnt + 1]));
if _id <> 0 then
begin
jDrawChar(_x, _y, _dstW, _dstH, _id, _xor, _hdc);
inc(_cnt, 1);
if _vert = false
then inc(_x, _dstW shr 1);
{ else inc(_y, _dstH); }
end else begin
_chr := byte(_text[_cnt]) + 1;
_chr := jHispaFilter(_chr);
aDrawChar(_x, _y, _dstW shr 1, _dstH,
_chr, _xor, _hdc);
end;
end;
inc(_cnt);
if _vert = false
then inc(_x, _dstW shr 1)
else inc(_y, _dstH);
until _cnt > length(_text);
jWriteSJS := _r;
end;
// --------------------------------------------------------------------
function jWriteEUC(_x, _y: integer; _dstW, _dstH: word;
_text: string; _vert, _xor: boolean;
_hdc: HDC): boolean;
// Don't use a constant as _text with Delphi,
// use only strings!
begin
jWriteEUC := jWriteSJS(_x, _y, _dstW, _dstH, jEUC2SJS(_text),
_vert, _xor, _hdc);
end;
// --------------------------------------------------------------------
function jBreakSJS(_text: string; _length: word): string;
// Break a SJS chain
var _cnt : word;
_id : word;
_z, _x : boolean;
_spc : word;
begin
_z := false;
_x := false;
_spc := 0;
{ jDoubleSpaceFilter(_text);}
_cnt := 1;
if length(_text) > 0 then
repeat
if (_cnt <= length(_text)) then
begin
if _cnt = length(_text) then _id := 0
else _id := jChooseChar((byte(_text[_cnt]) shl 8)
+ byte(_text[_cnt + 1]));
if _id <> 0
then inc(_cnt, 1)
else begin
if (_text[_cnt] = BRK00)
or (_text[_cnt] = BRK01) then _spc := _cnt;
end;
if (_cnt - 1 = _length - 1) and (_id <> 0) then _x := true;
if (_cnt - 1 = _length) and (_id <> 0) then _z := true;
end;
inc(_cnt);
until _cnt > length(_text);
if _x = false then
if _z = true then dec(_length)
else if (_spc > 0) and (_spc < _length) then _length := _spc;
SetLength(_text, _length);
jBreakSJS := _text;
end;
// --------------------------------------------------------------------
function jInitialize: boolean;
var _r : boolean;
_c : byte;
begin
_r := true;
// Init jKANJIS
for _c := 137 to 151 do jKANJIS[_c - 136] := _c;
for _c := 153 to 159 do jKANJIS[_c - 137] := _c;
for _c := 224 to 233 do jKANJIS[_c - 201] := _c;
// Load FNTs
if jLoadFile(ExtractFileDir(paramstr(0)) +'\'+ jJAPFNT,
@jCHARS) = false then _r := false;
if jLoadFile(ExtractFileDir(paramstr(0)) +'\'+ jASCFNT,
@aCHARS) = false then _r := false;
// Create BMPs
jASC := CreateBitmap(16, 16, 1, 1, NIL); // Yes, it's Ok (isn't 8)
if jASC = NULL then _r := false;
jPIC := CreateBitmap(16, 16, 1, 1, NIL);
if jPIC = NULL then _r := false;
// Create DCs
jASCDC := CreateCompatibleDC(GetDC(GetDesktopWindow));
if jASCDC = NULL then _r := false;
jPICDC := CreateCompatibleDC(GetDC(GetDesktopWindow));
if jPICDC = NULL then _r := false;
// Select Objects
if SelectObject(jASCDC, jASC) = NULL then _r := false;
if SelectObject(jPICDC, jPIC) = NULL then _r := false;
// All ok
jInitialize := _r;
end;
// --------------------------------------------------------------------
procedure jClose;
begin
// Delete DCs
DeleteDC(jASCDC);
DeleteDC(jPICDC);
// Delete BMPs
DeleteObject(jASC);
DeleteObject(jPIC);
end;
// --------------------------------------------------------------------
END.