hedgewars/uUtils.pas
changeset 4380 b78638b36b89
parent 4374 bcefeeabaa33
child 4385 f679ffa2dc8c
equal deleted inserted replaced
4379:6cd6b77df8b8 4380:b78638b36b89
    29 
    29 
    30 function  isPowerOf2(i: Longword): boolean;
    30 function  isPowerOf2(i: Longword): boolean;
    31 function  toPowerOf2(i: Longword): Longword; inline;
    31 function  toPowerOf2(i: Longword): Longword; inline;
    32 
    32 
    33 function  endian(independent: LongWord): LongWord; inline;
    33 function  endian(independent: LongWord): LongWord; inline;
       
    34 
       
    35 function  CheckCJKFont(s: ansistring; font: THWFont): THWFont;
    34 
    36 
    35 {$IFDEF DEBUGFILE}
    37 {$IFDEF DEBUGFILE}
    36 procedure AddFileLog(s: shortstring);
    38 procedure AddFileLog(s: shortstring);
    37 {$ENDIF}
    39 {$ENDIF}
    38 
    40 
   225 writeln(f, GameTicks: 6, ': ', s);
   227 writeln(f, GameTicks: 6, ': ', s);
   226 flush(f)
   228 flush(f)
   227 end;
   229 end;
   228 {$ENDIF}
   230 {$ENDIF}
   229 
   231 
       
   232 
       
   233 function CheckCJKFont(s: ansistring; font: THWFont): THWFont;
       
   234 var l, i : LongInt;
       
   235     u: WideChar;
       
   236     tmpstr: array[0..256] of WideChar;
       
   237 begin
       
   238 
       
   239 {$IFNDEF IPHONEOS}
       
   240 // remove chinese fonts for now
       
   241 if (font >= CJKfnt16) or (length(s) = 0) then
       
   242 {$ENDIF}
       
   243     exit(font);
       
   244 
       
   245 l:= Utf8ToUnicode(@tmpstr, Str2PChar(s), length(s))-1;
       
   246 i:= 0;
       
   247 while i < l do
       
   248     begin
       
   249     u:= tmpstr[i];
       
   250     if (#$2E80  <= u) and  (
       
   251                            (u <= #$2FDF )  or // CJK Radicals Supplement / Kangxi Radicals
       
   252        ((#$2FF0  <= u) and (u <= #$303F))  or // Ideographic Description Characters / CJK Radicals Supplement
       
   253        ((#$31C0  <= u) and (u <= #$31EF))  or // CJK Strokes
       
   254        ((#$3200  <= u) and (u <= #$4DBF))  or // Enclosed CJK Letters and Months / CJK Compatibility / CJK Unified Ideographs Extension A
       
   255        ((#$4E00  <= u) and (u <= #$9FFF))  or // CJK Unified Ideographs
       
   256        ((#$F900  <= u) and (u <= #$FAFF))  or // CJK Compatibility Ideographs
       
   257        ((#$FE30  <= u) and (u <= #$FE4F)))    // CJK Compatibility Forms
       
   258        then exit(THWFont( ord(font) + ((ord(High(THWFont))+1) div 2) ));
       
   259     inc(i)
       
   260     end;
       
   261 exit(font);
       
   262 (* two more to check. pascal WideChar is only 16 bit though
       
   263        ((#$20000 <= u) and (u >= #$2A6DF)) or // CJK Unified Ideographs Extension B
       
   264        ((#$2F800 <= u) and (u >= #$2FA1F)))   // CJK Compatibility Ideographs Supplement *)
       
   265 end;
   230 
   266 
   231 procedure initModule;
   267 procedure initModule;
   232 {$IFDEF DEBUGFILE}{$IFNDEF IPHONEOS}var i: LongInt;{$ENDIF}{$ENDIF}
   268 {$IFDEF DEBUGFILE}{$IFNDEF IPHONEOS}var i: LongInt;{$ENDIF}{$ENDIF}
   233 begin
   269 begin
   234 {$IFDEF DEBUGFILE}
   270 {$IFDEF DEBUGFILE}