Юрий Карпов - Пишем программу для создания книг FB2.
- Название:Пишем программу для создания книг FB2.
- Автор:
- Жанр:
- Издательство:неизвестно
- Год:неизвестен
- ISBN:нет данных
- Рейтинг:
- Избранное:Добавить в избранное
-
Ваша оценка:
Юрий Карпов - Пишем программу для создания книг FB2. краткое содержание
Подробный комментарий к исходному коду программы создающей книжку в формате FB2.
Пишем программу для создания книг FB2. - читать онлайн бесплатно полную версию (весь текст целиком)
Шрифт:
Интервал:
Закладка:
inc(EndNotes_count); // увеличиваем счетчик сносок
end;
'^': S:= S + '́'; // ставим ударение
else S:= S + ss[j];
end; // case
end;
if (S = '') and (CurStyle <> Poem)
then
begin
OutList.Add('');
continue;
end;
if (CurStyle <> oldStyle) and (CurStyle <> Auth) then
begin
case oldStyle of // завершение предыдущего блока
Poem: OutList.Add('');
Epig: OutList.Add('');
Citat: OutList.Add('');
H1..H5: OutList.Add('');
end; // case завершение предыдущего блока
case CurStyle of // начало блока
Poem: OutList.Add('');
Epig: OutList.Add('');
Citat: OutList.Add('');
end; // case начало блока
end;
// анализ стилей
case CurStyle of // в зависимости от стиля абзаца
Norm,Epig,Citat: OutList.Add('
'+S+'
');H1..H5: StyleStucture; // Heading
Sub: OutList.Add(''+s+''); // Subtitle
Poem: begin
if S = ''
then OutList.Add('')
else OutList.Add(''+S+'');
end;
Auth: begin
OutList.Add(''+S+'');
if oldStyle in [Poem, Epig, Citat]
then CurStyle:= oldStyle;
end;
None: continue; //None
end; // case
oldStyle:= CurStyle;
end; // for просмотр текста
if SytleStack.Count > 0 then
begin // закрываем все открытые секции
while SytleStack.Count > 0 do
begin
SytleStack.Delete(SytleStack.Count-1);
OutList.Add('
');end;
end;
OutList.Add('
');OutList.Add('
');end;
procedure SaveEndnotes;
var
S: string;
i: integer;
begin
if Form1.EndNotesList.Items.Count = 0 then exit; //[1]
OutList.Add('
Примечания
');for i:= 0 to Form1.EndNotesList.Items.Count - 1 do
begin
S:= Form1.EndNotesList.Items[i];
OutList.Add('
'+IntToStr(i+1)+'
');OutList.Add('
'+S+'
');OutList.Add('
');end;
OutList.Add('
');end;
Procedure Make_fb2(S: string);
begin //
if Form1.ListBox1.Items.Count = 0 then exit;
SytleStack.Clear;
OutList.Clear;
SaveDescription;
SaveBodyFB2;
SaveEndnotes;
OutList.Add('');
OutList.SaveToFile(S); //++ +
showMessage('Done.');
end;
function BookHaveName: boolean;
begin
with Form1 do
result:= (book_title.Text <> '') and
(FB2_file.Text <> '') and
(GenresBox.Count > 0);
end;
procedure TForm1.SaveasFB21Click(Sender: TObject);
begin
if not BookHaveName then
begin
PageControl1.ActivePageIndex:= 0;
ShowMessage('Fill the form.');
exit;
end;
SaveDialog1.FileName:= form1.FB2_file.Text;
if SaveDialog1.Execute then
Make_fb2(SaveDialog1.FileName);
end;
function SetStyle(n: TmyStyle):string;
begin
case n of
Norm: result:= ' N';
Epig: result:= ' E';
Auth: result:= ' A';
H1: result:= 'H1';
H2: result:= 'H2';
H3: result:= 'H3';
H4: result:= 'H4';
H5: result:= 'H5';
Sub: result:= ' S';
Poem: result:= ' P';
Citat: result:= ' C';
None: result:= '-';
end; // case
end;
function SetStyle1(n: TmyStyle):string;
begin
result:= ' '+ SetStyle(n)+'| ';
end;
procedure ChangeStyle(LStyle: TmyStyle);
var
n, curIndex: integer;
S: string;
begin
with Form1.ListBox1 do
begin
curIndex:= ItemIndex;
if curIndex = -1 then exit;
S:= Items[curIndex];
n:= pos('|', s);
delete(S, 1, n+1);
Items[curIndex]:= SetStyle1(LStyle)+ S;
if ItemIndex < Items.Count - 1
then ItemIndex:= ItemIndex+1;
SetFocus;
end;
end;
procedure TForm1.Button12Click(Sender: TObject);
begin
ChangeStyle(TmyStyle(RG.itemindex));
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
Form3.ListBox1.Items.Assign(GenresBox.Items);
Form3.ShowModal;
if Form3.ModalResult = mrOK then
begin
GenresBox.Items.Assign(Form3.ListBox1.Items);
end;
end;
procedure TForm1.Button10Click(Sender: TObject);
begin
Form2.ListBox1.Items.Assign(ListBox3.Items);
Form2.Button1Click(nil);
Form2.ShowModal;
if Form2.ModalResult = mrOK then
begin
ListBox3.Items.Assign(Form2.ListBox1.Items);
end;
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
Form2.ListBox1.Items.Assign(ListBox2.Items);
Form2.Button1Click(nil);
Form2.ShowModal;
if Form2.ModalResult = mrOK then
begin
ListBox2.Items.Assign(Form2.ListBox1.Items);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
Path:= ExtractFileDir(ParamStr(0)) + '\';
OpenDialog1.InitialDir:= Path;
for i:= 0 to maxL do
SLang.Items.Add(Lg[i][2]);
SLang.ItemIndex:= 0;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if FileExists(Path + 'EndNotes.txt')
then EndNotesList.Items.LoadFromFile(Path + 'EndNotes.txt');
end;
procedure TForm1.Button9Click(Sender: TObject);
begin
if FileExists(Path + 'Annotation.txt') then
Annotation.Lines.LoadFromFile(Path + 'Annotation.txt');
end;
function ScanUpStyle(n: integer):TmyStyle;
var
i: integer;
LStyle: TmyStyle;
begin
with Form1.ListBox1 do
for i:= n downto 0 do
begin
GetStyle(Items[i], LStyle);
if LStyle in [H1..H5] then
begin
result:= LStyle;
exit;
end;
end;
result:= H1;
end;
procedure ShowHeadStyle(n: integer);
var
LStyle: TmyStyle;
begin
LStyle:= ScanUpStyle(n);
Form1.Button2.Caption:= SetStyle(LStyle);
Form1.Button2.Tag:= integer(LStyle);
end;
procedure TForm1.ListBox1DblClick(Sender: TObject);
var
S: string;
CurStyle: TmyStyle;
i, st: integer;
begin
st:= ListBox1.itemIndex;
S:= GetStyle(ListBox1.Items[st], CurStyle);
with EditSt do
begin
Memo1.WordWrap:= true;
Memo1.Clear;
Memo1.Lines.Add(S);
ShowModal;
if ModalResult = mrOK then
begin
ListBox1.Items.Delete(st);
Memo1.WordWrap:= false;
for i:= Memo1.Lines.Count - 1 downto 0 do
ListBox1.Items.Insert(st, SetStyle1(CurStyle)+Memo1.Lines[i]);
end;
end;
end;
procedure TForm1.ListBox1Click(Sender: TObject);
begin
ShowHeadStyle(ListBox1.itemIndex);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ChangeStyle(TmyStyle(Button2.Tag));
end;
procedure TForm1.Button5Click(Sender: TObject);
var
LStyle: TmyStyle;
begin
LStyle:= TmyStyle(Button2.Tag);
if LStyle < H5 then ChangeStyle(Succ(LStyle));
end;
procedure TForm1.Button1Click(Sender: TObject);
var
LStyle: TmyStyle;
begin
LStyle:= TmyStyle(Button2.Tag);
if LStyle > H1 then ChangeStyle(Pred(LStyle));
end;
end.
// конец кода
genres.dfm
// начало кода
object Form3: TForm3
Left = 214
Top = 121
BorderIcons = [biSystemMenu, biMinimize]
BorderStyle = bsSingle
Caption = 'Genre'
ClientHeight = 294
ClientWidth = 603
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object ListBox1: TListBox
Left = 8
Top = 8
Width = 241
Height = 209
ItemHeight = 13
TabOrder = 0
end
object Button1: TButton
Left = 272
Top = 32
Width = 75
Height = 25
Caption = 'Add'
TabOrder = 1
OnClick = Button1Click
end
object Button2: TButton
Left = 272
Top = 64
Width = 75
Height = 25
Caption = 'Delete'
TabOrder = 2
OnClick = Button2Click
end
object BitBtn1: TBitBtn
Left = 80
Top = 248
Width = 75
Height = 25
TabOrder = 3
Kind = bkOK
end
object BitBtn2: TBitBtn
Left = 448
Top = 240
Width = 75
Height = 25
TabOrder = 4
Kind = bkCancel
end
object Button3: TButton
Left = 272
Top = 112
Width = 75
Height = 25
Caption = 'Up'
TabOrder = 5
OnClick = Button3Click
end
object Button4: TButton
Left = 272
Top = 152
Width = 75
Height = 25
Caption = 'Down'
TabOrder = 6
OnClick = Button4Click
end
object ListBox2: TListBox
Left = 368
Top = 32
Width = 225
Height = 185
ItemHeight = 13
TabOrder = 7
OnDblClick = ListBox2DblClick
end
object ComboBox1: TComboBox
Left = 368
Top = 8
Width = 225
Height = 21
ItemHeight = 13
ItemIndex = 0
TabOrder = 8
Text = #1044#1077#1083#1086#1074#1072#1103' '#1083#1080#1090#1077#1088#1072#1090#1091#1088#1072
OnChange = ComboBox1Change
Items.Strings = (
#1044#1077#1083#1086#1074#1072#1103' '#1083#1080#1090#1077#1088#1072#1090#1091#1088#1072
#1044#1077#1090#1077#1082#1090#1080#1074#1099' '#1080' '#1058#1088#1080#1083#1083#1077#1088#1099
#1044#1077#1090#1089#1082#1086#1077
#1044#1086#1082#1091#1084#1077#1085#1090#1072#1083#1100#1085#1072#1103' '#1083#1080#1090#1077#1088#1072#1090#1091#1088#1072
#1044#1086#1084#1086#1074#1086#1076#1089#1090#1074#1086
#1050#1086#1084#1087#1100#1102#1090#1077#1088#1099' '#1080' '#1048#1085#1090#1077#1088#1085#1077#1090
#1051#1102#1073#1086#1074#1085#1099#1077' '#1088#1086#1084#1072#1085#1099
#1053#1072#1091#1082#1072', '#1054#1073#1088#1072#1079#1086#1074#1072#1085#1080#1077
#1055#1077#1088#1080#1086#1076#1080#1082#1072
#1055#1086#1101#1079#1080#1103', '#1044#1088#1072#1084#1072#1090#1091#1088#1075#1080#1103
#1055#1088#1080#1082#1083#1102#1095#1077#1085#1080#1103
#1055#1088#1086#1079#1072
#1055#1088#1086#1095#1077#1077
#1056#1077#1083#1080#1075#1080#1103' '#1080' '#1076#1091#1093#1086#1074#1085#1086#1089#1090#1100
#1057#1087#1088#1072#1074#1086#1095#1085#1072#1103' '#1083#1080#1090#1077#1088#1072#1090#1091#1088#1072
#1057#1090#1072#1088#1080#1085#1085#1086#1077
#1058#1077#1093#1085#1080#1082#1072
#1060#1072#1085#1090#1072#1089#1090#1080#1082#1072
#1070#1084#1086#1088)
end
end
// конец кода
genres.pas
// начало кода
unit genres;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, StdCtrls, dm;
type
TForm3 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
Button2: TButton;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Button3: TButton;
Button4: TButton;
ListBox2: TListBox;
ComboBox1: TComboBox;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
Шрифт:
Интервал:
Закладка: