61 lines
1.7 KiB
Plaintext
61 lines
1.7 KiB
Plaintext
type TSNoteWare = class
|
|
public
|
|
function Create(sect_ware: TSSectWare);
|
|
function GetFootnoteOrderNumber(): string;
|
|
function GetIndex(): string;
|
|
|
|
private
|
|
function CalculateNumber(num_fmt: string; num: integer): string;
|
|
function ChineseCountingThousand(n: integer): string;
|
|
|
|
private
|
|
[weakref]sect_ware_: TSSectWare;
|
|
index_: integer;
|
|
end;
|
|
|
|
function TSNoteWare.Create(sect_ware: TSSectWare);
|
|
begin
|
|
sect_ware_ := sect_ware;
|
|
index_ := 0;
|
|
end;
|
|
|
|
function TSNoteWare.GetFootnoteOrderNumber();
|
|
begin
|
|
num_fmt := sect_ware_.SectPr.FootnotePr.NumFmt.Val;
|
|
if ifnil(num_fmt) then num_fmt := "decimal";
|
|
return CalculateNumber(num_fmt, ++index_);
|
|
end;
|
|
|
|
function TSNoteWare.GetIndex(): string;
|
|
begin
|
|
return inttostr(index_);
|
|
end;
|
|
|
|
function TSNoteWare.CalculateNumber(num_fmt: string; num: integer): string;
|
|
begin
|
|
if num_fmt = "decimal" then
|
|
return format("%d", num);
|
|
else if num_fmt = "chineseCountingThousand" then
|
|
return {self.}ChineseCountingThousand(num);
|
|
else
|
|
return format("%d", num);
|
|
end;
|
|
|
|
function TSNoteWare.ChineseCountingThousand(n: integer): string;
|
|
begin
|
|
chinese_digits := array("零", "一", "二", "三", "四", "五", "六", "七", "八", "九");
|
|
chinese_units := array("", "十", "百", "千");
|
|
if n < 10 then return chinese_digits[n];
|
|
result := "";
|
|
num_str := inttostr(n);
|
|
len := length(num_str);
|
|
for i:=1 to len do
|
|
begin
|
|
digit_int := strtoint(num_str[i]);
|
|
if digit_int <> 0 then
|
|
result += chinese_digits[digit_int] + chinese_units[len - i];
|
|
end
|
|
if length(result) >= 6 and result[:6] = "一十" then result := result[4:];
|
|
return result;
|
|
end;
|