Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
proview
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Esteban Blanc
proview
Commits
f5d29d96
Commit
f5d29d96
authored
Sep 25, 2007
by
claes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cnv-lib didn't work as gtk-image was buildt with motif...
parent
f01066df
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
1538 additions
and
2 deletions
+1538
-2
xtt/lib/flow/src/flow_pdf.cpp
xtt/lib/flow/src/flow_pdf.cpp
+2
-2
xtt/lib/flow/src/flow_topdf.cpp
xtt/lib/flow/src/flow_topdf.cpp
+1221
-0
xtt/lib/flow/src/flow_topdf.h
xtt/lib/flow/src/flow_topdf.h
+315
-0
No files found.
xtt/lib/flow/src/flow_pdf.cpp
View file @
f5d29d96
/*
/*
* Proview $Id: flow_pdf.cpp,v 1.
1 2007-09-25 13:11:00
claes Exp $
* Proview $Id: flow_pdf.cpp,v 1.
2 2007-09-25 14:23:51
claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
* Copyright (C) 2005 SSAB Oxelsund AB.
*
*
* This program is free software; you can redistribute it and/or
* This program is free software; you can redistribute it and/or
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
#include <float.h>
#include <float.h>
#include "flow_ctx.h"
#include "flow_ctx.h"
#include "flow_pdf.h"
#include "flow_pdf.h"
#include "
cnv
_topdf.h"
#include "
flow
_topdf.h"
FlowPdf
::
FlowPdf
(
char
*
filename
,
void
*
flow_ctx
,
int
page_border
,
FlowPdf
::
FlowPdf
(
char
*
filename
,
void
*
flow_ctx
,
int
page_border
,
int
*
sts
)
:
int
*
sts
)
:
...
...
xtt/lib/flow/src/flow_topdf.cpp
0 → 100644
View file @
f5d29d96
/*
* Proview $Id: flow_topdf.cpp,v 1.1 2007-09-25 14:23:51 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* cnv_topdf.cpp --
This file is a copy of cnv_topdf.cpp and cnv_content.cpp with the
gdk_image calls removed.
*/
/*_Include files_________________________________________________________*/
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
extern
"C"
{
#include "co_cdh.h"
#include "co_dcli.h"
}
#include "flow_topdf.h"
#include "co_lng.h"
//#include "cnv_image.h"
#define CNV_TAB 18
#define pdf_cHead "%PDF-1.4"
/* Nice functions */
#define ODD(a) (((int)(a) & 1) != 0)
#define EVEN(a) (((int)(a) & 1) == 0)
#define max(Dragon,Eagle) ((Dragon) > (Eagle) ? (Dragon) : (Eagle))
#define min(Dragon,Eagle) ((Dragon) < (Eagle) ? (Dragon) : (Eagle))
#ifndef __ALPHA
#define abs(Dragon) ((Dragon) >= 0 ? (Dragon) : (-(Dragon)))
#endif
int
CnvContent
::
find_link
(
char
*
subject
,
char
*
text
,
int
*
page
)
{
char
key_part
[
4
][
40
];
char
subject_part
[
4
][
40
];
int
i
,
j
;
int
subject_nr
;
int
key_nr
;
int
hit
=
0
;
subject_nr
=
dcli_parse
(
subject
,
" "
,
""
,
(
char
*
)
subject_part
,
sizeof
(
subject_part
)
/
sizeof
(
subject_part
[
0
]),
sizeof
(
subject_part
[
0
]),
0
);
for
(
j
=
0
;
j
<
(
int
)
tab
.
size
();
j
++
)
{
key_nr
=
dcli_parse
(
tab
[
j
].
subject
,
" "
,
""
,
(
char
*
)
key_part
,
sizeof
(
key_part
)
/
sizeof
(
key_part
[
0
]),
sizeof
(
key_part
[
0
]),
0
);
if
(
key_nr
==
subject_nr
)
{
for
(
i
=
0
;
i
<
key_nr
;
i
++
)
{
if
(
cdh_NoCaseStrcmp
(
subject_part
[
i
],
key_part
[
i
])
==
0
)
{
if
(
i
==
key_nr
-
1
)
{
hit
=
1
;
break
;
}
}
else
break
;
}
}
if
(
hit
)
break
;
}
if
(
!
hit
)
return
0
;
strcpy
(
text
,
tab
[
j
].
text
);
*
page
=
tab
[
j
].
page_number
;
return
1
;
}
void
CnvContent
::
add
(
CnvContentElem
&
elem
)
{
tab
.
push_back
(
elem
);
}
void
CnvPdfObj
::
print_begin
()
{
offset
=
topdf
->
fp
[
topdf
->
cf
].
tellp
();
switch
(
type
)
{
case
pdf_eObjType_Catalog
:
topdf
->
fp
[
topdf
->
cf
]
<<
number
<<
" 0 obj"
<<
endl
<<
" << /Type /Catalog"
<<
endl
<<
" /Outlines 2 0 R"
<<
endl
<<
" /Pages "
<<
number
+
topdf
->
v_outline
.
size
()
<<
" 0 R"
<<
endl
;
if
(
topdf
->
use_outlines
)
topdf
->
fp
[
topdf
->
cf
]
<<
" /PageMode /UseOutlines"
<<
endl
;
topdf
->
fp
[
topdf
->
cf
]
<<
" >>"
<<
endl
<<
"endobj"
<<
endl
<<
endl
;
break
;
case
pdf_eObjType_Outline
:
topdf
->
fp
[
topdf
->
cf
]
<<
number
<<
" 0 obj"
<<
endl
<<
" << /Type /Outlines"
<<
endl
;
if
(
first
)
topdf
->
fp
[
topdf
->
cf
]
<<
" /First "
<<
first
+
1
<<
" 0 R"
<<
endl
;
if
(
last
)
topdf
->
fp
[
topdf
->
cf
]
<<
" /Last "
<<
last
+
1
<<
" 0 R"
<<
endl
;
topdf
->
fp
[
topdf
->
cf
]
<<
" /Count "
<<
count
<<
endl
<<
" >>"
<<
endl
<<
"endobj"
<<
endl
<<
endl
;
break
;
case
pdf_eObjType_Pages
:
topdf
->
fp
[
topdf
->
cf
]
<<
number
+
topdf
->
v_outline
.
size
()
<<
" 0 obj"
<<
endl
<<
" << /Type /Pages"
<<
endl
<<
" /Kids ["
<<
endl
;
for
(
int
i
=
1
;
i
<
(
int
)
topdf
->
v_pages
.
size
();
i
++
)
topdf
->
fp
[
topdf
->
cf
]
<<
" "
<<
topdf
->
v_outline
.
size
()
+
topdf
->
v_pages
[
i
].
number
<<
" 0 R"
<<
endl
;
topdf
->
fp
[
topdf
->
cf
]
<<
" ]"
<<
endl
<<
" /Count "
<<
topdf
->
v_pages
.
size
()
-
1
<<
endl
<<
" >>"
<<
endl
<<
"endobj"
<<
endl
<<
endl
;
break
;
case
pdf_eObjType_Page
:
topdf
->
fp
[
topdf
->
cf
]
<<
number
+
topdf
->
v_outline
.
size
()
<<
" 0 obj"
<<
endl
<<
" << /Type /Page"
<<
endl
<<
" /Parent "
<<
topdf
->
v_outline
.
size
()
+
1
<<
" 0 R"
<<
endl
<<
" /Mediabox [0 0 "
<<
pdf_cPageWidth
<<
" "
<<
pdf_cPageHeight
<<
"]"
<<
endl
<<
" /Contents "
<<
number
-
1
+
topdf
->
v_outline
.
size
()
+
topdf
->
v_pages
.
size
()
<<
" 0 R"
<<
endl
;
if
(
resource
==
-
1
)
{
topdf
->
fp
[
topdf
->
cf
]
<<
" /Resources << /Procset "
<<
topdf
->
v_outline
.
size
()
+
topdf
->
v_pages
.
size
()
+
topdf
->
v_content
.
size
()
+
1
<<
" 0 R"
<<
endl
<<
" /Font <<"
<<
endl
;
for
(
int
i
=
1
;
i
<
(
int
)
topdf
->
v_font
.
size
();
i
++
)
topdf
->
fp
[
topdf
->
cf
]
<<
" /F"
<<
topdf
->
v_font
[
i
].
number
-
1
<<
" "
<<
topdf
->
v_font
[
i
].
number
+
topdf
->
v_outline
.
size
()
+
topdf
->
v_pages
.
size
()
+
topdf
->
v_content
.
size
()
<<
" 0 R"
<<
endl
;
topdf
->
fp
[
topdf
->
cf
]
<<
" >>"
<<
endl
<<
" >>"
<<
endl
;
}
else
{
topdf
->
fp
[
topdf
->
cf
]
<<
" /Resources "
<<
topdf
->
v_outline
.
size
()
+
topdf
->
v_pages
.
size
()
+
topdf
->
v_content
.
size
()
+
+
topdf
->
v_font
.
size
()
+
resource
+
1
<<
" 0 R"
<<
endl
;
}
topdf
->
fp
[
topdf
->
cf
]
<<
" >>"
<<
endl
<<
"endobj"
<<
endl
<<
endl
;
break
;
case
pdf_eObjType_Content
:
topdf
->
fp
[
topdf
->
cf
]
<<
number
+
topdf
->
v_outline
.
size
()
+
topdf
->
v_pages
.
size
()
<<
" 0 obj"
<<
endl
<<
" << /Length "
<<
length
<<
" >>"
<<
endl
<<
"stream"
<<
endl
;
start
=
(
int
)
topdf
->
fp
[
topdf
->
cf
].
tellp
();
break
;
case
pdf_eObjType_Process
:
topdf
->
fp
[
topdf
->
cf
]
<<
number
+
topdf
->
v_outline
.
size
()
+
topdf
->
v_pages
.
size
()
+
topdf
->
v_content
.
size
()
<<
" 0 obj"
<<
endl
<<
" [/PDF /Text]"
<<
endl
<<
"endobj"
<<
endl
<<
endl
;
break
;
case
pdf_eObjType_Font
:
topdf
->
fp
[
topdf
->
cf
]
<<
number
+
topdf
->
v_outline
.
size
()
+
topdf
->
v_pages
.
size
()
+
topdf
->
v_content
.
size
()
<<
" 0 obj"
<<
endl
<<
" << /Type /Font"
<<
endl
<<
" /Subtype /Type1"
<<
endl
<<
" /Name /F"
<<
number
-
1
<<
endl
<<
" /BaseFont /"
<<
fontname
<<
endl
<<
" /Encoding /WinAnsiEncoding"
<<
endl
<<
" >>"
<<
endl
<<
"endobj"
<<
endl
<<
endl
;
break
;
case
pdf_eObjType_OutlineO
:
topdf
->
fp
[
topdf
->
cf
]
<<
number
<<
" 0 obj"
<<
endl
<<
" << /Title ("
<<
text
<<
")"
<<
endl
<<
" /Parent "
<<
parent
+
1
<<
" 0 R"
<<
endl
;
if
(
prev
)
topdf
->
fp
[
topdf
->
cf
]
<<
" /Prev "
<<
prev
+
1
<<
" 0 R"
<<
endl
;
if
(
next
)
topdf
->
fp
[
topdf
->
cf
]
<<
" /Next "
<<
next
+
1
<<
" 0 R"
<<
endl
;
if
(
first
)
topdf
->
fp
[
topdf
->
cf
]
<<
" /First "
<<
first
+
1
<<
" 0 R"
<<
endl
;
if
(
last
)
topdf
->
fp
[
topdf
->
cf
]
<<
" /Last "
<<
last
+
1
<<
" 0 R"
<<
endl
;
if
(
count
)
topdf
->
fp
[
topdf
->
cf
]
<<
" /Count "
<<
count
<<
endl
;
topdf
->
fp
[
topdf
->
cf
]
<<
" /Dest ["
<<
dest
<<
" 0 R /XYZ null 700 null]"
<<
endl
<<
" >>"
<<
endl
<<
"endobj"
<<
endl
<<
endl
;
break
;
case
pdf_eObjType_Image
:
print_image
();
break
;
case
pdf_eObjType_Resource
:
topdf
->
fp
[
topdf
->
cf
]
<<
number
+
topdf
->
v_outline
.
size
()
+
topdf
->
v_pages
.
size
()
+
topdf
->
v_content
.
size
()
+
topdf
->
v_font
.
size
()
<<
" 0 obj"
<<
endl
<<
" << /ProcSet [/PDF /Text /ImageB]"
<<
endl
<<
" /XObject <<"
<<
endl
;
for
(
int
i
=
0
;
i
<
xobject_cnt
;
i
++
)
{
topdf
->
fp
[
topdf
->
cf
]
<<
" /Im"
<<
xobject
[
i
]
+
1
<<
" "
<<
xobject
[
i
]
+
1
+
topdf
->
v_outline
.
size
()
+
topdf
->
v_pages
.
size
()
+
topdf
->
v_content
.
size
()
+
topdf
->
v_font
.
size
()
+
topdf
->
v_resource
.
size
()
<<
" 0 R"
<<
endl
;
}
topdf
->
fp
[
topdf
->
cf
]
<<
" >>"
<<
endl
<<
" /Font <<"
<<
endl
;
for
(
int
i
=
1
;
i
<
(
int
)
topdf
->
v_font
.
size
();
i
++
)
topdf
->
fp
[
topdf
->
cf
]
<<
" /F"
<<
topdf
->
v_font
[
i
].
number
-
1
<<
" "
<<
topdf
->
v_font
[
i
].
number
+
topdf
->
v_outline
.
size
()
+
topdf
->
v_pages
.
size
()
+
topdf
->
v_content
.
size
()
<<
" 0 R"
<<
endl
;
topdf
->
fp
[
topdf
->
cf
]
<<
" >>"
<<
endl
<<
" >>"
<<
endl
<<
"endobj"
<<
endl
;
break
;
}
}
void
CnvPdfObj
::
print_end
()
{
switch
(
type
)
{
case
pdf_eObjType_Content
:
length
=
(
int
)
topdf
->
fp
[
topdf
->
cf
].
tellp
()
-
start
;
topdf
->
fp
[
topdf
->
cf
]
<<
"endstream"
<<
endl
<<
"endobj"
<<
endl
<<
endl
;
break
;
default:
;
}
}
int
CnvPdfObj
::
print_image
()
{
#if 0
cnv_tImImage image;
cnv_tPixmap pixmap;
pwr_tFileName fname;
int sts;
int width, height;
#if 0
unsigned char *rgb;
unsigned char transp[3] = {255,0,255};
int i, j;
int grey;
#endif
char c;
// Try $pwr_doc/help/
strcpy( fname, "$pwr_doc/help/");
strcat( fname, text);
dcli_translate_filename( fname, fname);
sts = cnv_get_image( fname, &image, &pixmap);
if ( EVEN(sts)) {
// Try $pwr_exe
strcpy( fname, "$pwr_exe/");
strcat( fname, text);
dcli_translate_filename( fname, fname);
sts = cnv_get_image( fname, &image, &pixmap);
if ( EVEN(sts)) {
// Try $pwrp_exe
strcpy( fname, "$pwrp_exe/");
strcat( fname, text);
dcli_translate_filename( fname, fname);
sts = cnv_get_image( fname, &image, &pixmap);
if ( EVEN(sts)) return 0;
}
}
width = cnv_image_width( image);
height = cnv_image_height( image);
topdf->fp[topdf->cf] <<
number + topdf->v_outline.size() + topdf->v_pages.size() + topdf->v_content.size() +
topdf->v_font.size() + topdf->v_resource.size() << " 0 obj" << endl <<
" << /Type /XObject" << endl <<
" /Subtype /Image" << endl <<
" /Width " << width << endl <<
" /Height " << height << endl <<
" /ColorSpace /DeviceRGB" << endl <<
" /BitsPerComponent 8" << endl <<
" /Filter /DCTDecode" << endl <<
" /Length " << length << endl <<
" >>" << endl <<
"stream" << endl;
start = (int) topdf->fp[topdf->cf].tellp();
strcpy( fname, "/tmp/pwr_cnv.jpg");
cnv_print_image( image, fname);
ifstream fimg( fname);
while ( fimg.get(c))
topdf->fp[topdf->cf].put(c);
topdf->fp[topdf->cf] << endl;
length = (int) topdf->fp[topdf->cf].tellp() - start;
topdf->fp[topdf->cf] <<
"endstream" << endl <<
"endobj" << endl;
cnv_free_image( image, pixmap);
#endif
return
1
;
}
void
CnvToPdf
::
cnv_text
(
char
*
to
,
char
*
from
)
{
if
(
!
from
)
{
strcpy
(
to
,
""
);
return
;
}
char
*
t
=
to
;
char
*
s
=
from
;
for
(
;
*
s
;
s
++
)
{
switch
(
*
s
)
{
case
'('
:
*
t
++
=
'\\'
;
*
t
++
=
'('
;
break
;
case
')'
:
*
t
++
=
'\\'
;
*
t
++
=
')'
;
break
;
case
'\\'
:
*
t
++
=
'\\'
;
*
t
++
=
'\\'
;
default:
*
t
++
=
*
s
;
}
}
*
t
=
0
;
}
void
CnvToPdf
::
print_text
(
char
*
text
,
CnvStyle
&
style
,
int
mode
)
{
char
str
[
1000
];
cnv_text
(
str
,
text
);
if
(
style
.
sidebreak
&&
mode
&
pdf_mPrintMode_Pos
)
{
if
(
page_number
[
cf
]
==
0
)
{
// First header, no pagebreak
page_number
[
cf
]
=
1
;
}
else
{
print_pagebreak
(
0
);
}
}
else
if
(
style
.
pagebreak
&&
mode
&
pdf_mPrintMode_Pos
)
{
print_pagebreak
(
0
);
}
if
(
mode
&
pdf_mPrintMode_Pos
||
mode
&
pdf_mPrintMode_Start
)
{
y
-=
style
.
top_offset
;
if
(
y
-
style
.
bottom_offset
<
pdf_cBottomMargin
)
{
print_pagebreak
(
0
);
}
}
else
y
+=
style
.
bottom_offset
;
if
(
!
(
mode
&
pdf_mPrintMode_FixX
))
{
if
(
style
.
alignment
==
cnv_eAlignment_Center
)
{
x
=
pdf_cLeftMargin
/
2
+
(
pdf_cPageWidth
-
pdf_cLeftMargin
/
2
)
/
2
-
0.50
*
strlen
(
text
)
*
style
.
font_size
/
2
;
if
(
x
<
pdf_cLeftMargin
/
2
)
x
=
pdf_cLeftMargin
/
2
;
}
else
x
=
pdf_cLeftMargin
+
style
.
indentation
;
}
int
pmode
=
mode
&
31
;
if
(
strcmp
(
text
,
""
)
!=
0
)
{
switch
(
pmode
)
{
case
pdf_mPrintMode_Pos
:
case
pdf_mPrintMode_KeepY
:
{
// Full path with beginning and end
fp
[
cf
]
<<
" BT"
<<
endl
<<
" "
<<
fontname
(
style
)
<<
" "
<<
style
.
font_size
<<
" Tf"
<<
endl
<<
" "
<<
x
<<
" "
<<
y
<<
" Td"
<<
endl
<<
" ("
<<
str
<<
") Tj"
<<
endl
<<
" ET"
<<
endl
;
break
;
}
case
pdf_mPrintMode_Start
:
{
// Start new path
fp
[
cf
]
<<
" BT"
<<
endl
<<
" "
<<
fontname
(
style
)
<<
" "
<<
style
.
font_size
<<
" Tf"
<<
endl
<<
" "
<<
x
<<
" "
<<
y
<<
" Td"
<<
endl
<<
" ("
<<
str
<<
") Tj"
<<
endl
;
break
;
}
case
pdf_mPrintMode_Continue
:
{
// Continue current path
fp
[
cf
]
<<
" "
<<
fontname
(
style
)
<<
" "
<<
style
.
font_size
<<
" Tf"
<<
endl
<<
" "
<<
x
<<
" "
<<
y
<<
" Td"
<<
endl
<<
" ("
<<
str
<<
") Tj"
<<
endl
;
break
;
}
case
pdf_mPrintMode_End
:
{
// Continue and close current path
fp
[
cf
]
<<
" "
<<
fontname
(
style
)
<<
" "
<<
style
.
font_size
<<
" Tf"
<<
endl
<<
" ("
<<
str
<<
") Tj"
<<
endl
<<
" ET"
<<
endl
;
break
;
}
default:
;
}
}
else
{
switch
(
pmode
)
{
case
pdf_mPrintMode_Start
:
{
// Start new path
fp
[
cf
]
<<
" BT"
<<
endl
<<
" "
<<
x
<<
" "
<<
y
<<
" Td"
<<
endl
;
break
;
}
case
pdf_mPrintMode_End
:
{
// Continue and close current path
fp
[
cf
]
<<
" ET"
<<
endl
;
break
;
}
default:
;
}
}
y
-=
style
.
bottom_offset
;
}
void
CnvToPdf
::
draw_rect
(
double
lw
,
double
x
,
double
y
,
double
w
,
double
h
)
{
fp
[
cf
]
<<
" "
<<
lw
<<
" w"
<<
endl
<<
" "
<<
x
<<
" "
<<
y
<<
" "
<<
w
<<
" "
<<
h
<<
" re S"
<<
endl
;
}
void
CnvToPdf
::
draw_arc
(
double
lw
,
double
x
,
double
y
,
double
w
,
double
h
,
int
angel1
,
int
angel2
)
{
fp
[
cf
]
<<
" "
<<
lw
<<
" w"
<<
endl
;
if
(
(
angel1
==
0
&&
angel2
>=
90
)
||
(
angel1
==
90
&&
angel2
>=
360
)
||
(
angel1
==
180
&&
angel2
>=
270
)
||
(
angel1
==
270
&&
angel2
>=
180
))
fp
[
cf
]
<<
" "
<<
x
+
w
<<
" "
<<
y
+
h
/
2
<<
" m"
<<
" "
<<
x
+
w
<<
" "
<<
y
+
h
<<
" "
<<
x
+
w
<<
" "
<<
y
+
h
<<
" "
<<
x
+
w
/
2
<<
" "
<<
y
+
h
<<
" "
<<
" c"
<<
endl
;
if
(
(
angel1
==
0
&&
angel2
>=
180
)
||
(
angel1
==
90
&&
angel2
>=
90
)
||
(
angel1
==
180
&&
angel2
>=
360
)
||
(
angel1
==
270
&&
angel2
>=
270
))
fp
[
cf
]
<<
" "
<<
x
+
w
/
2
<<
" "
<<
y
+
h
<<
" m"
<<
" "
<<
x
<<
" "
<<
y
+
h
<<
" "
<<
x
<<
" "
<<
y
+
h
<<
" "
<<
x
<<
" "
<<
y
+
h
/
2
<<
" "
<<
" c"
<<
endl
;
if
(
(
angel1
==
0
&&
angel2
>=
270
)
||
(
angel1
==
90
&&
angel2
>=
180
)
||
(
angel1
==
180
&&
angel2
>=
90
)
||
(
angel1
==
270
&&
angel2
>=
360
))
fp
[
cf
]
<<
" "
<<
x
<<
" "
<<
y
+
h
/
2
<<
" m"
<<
" "
<<
x
<<
" "
<<
y
<<
" "
<<
x
<<
" "
<<
y
<<
" "
<<
x
+
w
/
2
<<
" "
<<
y
<<
" "
<<
" c"
<<
endl
;
if
(
(
angel1
==
0
&&
angel2
>=
360
)
||
(
angel1
==
90
&&
angel2
>=
270
)
||
(
angel1
==
180
&&
angel2
>=
180
)
||
(
angel1
==
270
&&
angel2
>=
90
))
fp
[
cf
]
<<
" "
<<
x
+
w
/
2
<<
" "
<<
y
<<
" m"
<<
" "
<<
x
+
w
<<
" "
<<
y
<<
" "
<<
x
+
w
<<
" "
<<
y
<<
" "
<<
x
+
w
<<
" "
<<
y
+
h
/
2
<<
" "
<<
" c"
<<
endl
;
fp
[
cf
]
<<
" S"
<<
endl
;
}
void
CnvToPdf
::
draw_line
(
double
lw
,
double
x1
,
double
y1
,
double
x2
,
double
y2
,
int
dashed
,
int
gray
)
{
fp
[
cf
]
<<
" "
<<
lw
<<
" w"
<<
endl
;
if
(
dashed
)
fp
[
cf
]
<<
" [2 3] 1 d"
<<
endl
;
if
(
gray
)
fp
[
cf
]
<<
" 0.7 G"
<<
endl
;
fp
[
cf
]
<<
" "
<<
x1
<<
" "
<<
y1
<<
" m"
<<
endl
<<
" "
<<
x2
<<
" "
<<
y2
<<
" l S"
<<
endl
;
if
(
dashed
)
fp
[
cf
]
<<
" [] 0 d"
<<
endl
;
if
(
gray
)
fp
[
cf
]
<<
" 0 G"
<<
endl
;
}
void
CnvToPdf
::
draw_arrow
(
double
x1
,
double
y1
,
double
x2
,
double
y2
,
double
x3
,
double
y3
,
int
gray
)
{
if
(
gray
)
fp
[
cf
]
<<
" 0.7 G"
<<
endl
<<
" 0.7 g"
<<
endl
;
fp
[
cf
]
<<
" "
<<
x1
<<
" "
<<
y1
<<
" m"
<<
endl
<<
" "
<<
x2
<<
" "
<<
y2
<<
" l"
<<
endl
<<
" "
<<
x3
<<
" "
<<
y3
<<
" l"
<<
endl
<<
" "
<<
x1
<<
" "
<<
y1
<<
" l"
<<
endl
<<
" B"
<<
endl
;
if
(
gray
)
fp
[
cf
]
<<
" 0 G"
<<
endl
<<
" 0 g"
<<
endl
;
}
void
CnvToPdf
::
draw_text
(
double
x
,
double
y
,
char
*
text
,
int
bold
,
double
size
)
{
char
fontname
[
20
];
if
(
bold
)
strcpy
(
fontname
,
"/F2"
);
else
strcpy
(
fontname
,
"/F1"
);
fp
[
cf
]
<<
" BT"
<<
endl
<<
" "
<<
fontname
<<
" "
<<
size
<<
" Tf"
<<
endl
<<
" "
<<
x
<<
" "
<<
y
<<
" Td"
<<
endl
<<
" ("
<<
text
<<
") Tj"
<<
endl
<<
" ET"
<<
endl
;
}
void
CnvToPdf
::
print_pagebreak
(
int
last
)
{
if
(
page_number
[
cf
]
==
0
)
page_number
[
cf
]
=
1
;
if
(
page_number
[
cf
]
!=
1
||
last
)
{
double
page_x
;
page_x
=
pdf_cPageNumX
;
if
(
!
(
prev_ci
==
pdf_eId_TitlePage
||
prev_ci
==
pdf_eId_InfoPage
))
{
prev_ci
=
ci
;
fp
[
cf
]
<<
" 1 w"
<<
endl
<<
" "
<<
10
<<
" "
<<
pdf_cPageHeight
-
20
<<
" m"
<<
endl
<<
" "
<<
pdf_cPageWidth
+
65
<<
" "
<<
pdf_cPageHeight
-
20
<<
" l"
<<
endl
<<
" S"
<<
endl
<<
" BT"
<<
endl
<<
" /F1 10 Tf"
<<
endl
<<
" "
<<
pdf_cPageWidth
/
2
-
10
*
0.5
*
strlen
(
previous_chapter
)
<<
" "
<<
pdf_cPageNumY
<<
" Td"
<<
endl
<<
" ("
<<
previous_chapter
<<
") Tj"
<<
endl
<<
" ET"
<<
endl
<<
" BT"
<<
endl
<<
" /F1 10 Tf"
<<
endl
<<
" "
<<
page_x
<<
" "
<<
pdf_cPageNumY
<<
" Td"
<<
endl
<<
" ("
<<
page_number
[
cf
]
-
1
<<
") Tj"
<<
endl
<<
" ET"
<<
endl
;
}
if
(
page_number
[
cf
]
>
1
&&
v_content
.
size
()
>
0
)
v_content
[
page_number
[
cf
]
-
2
].
print_end
();
}
if
(
last
)
return
;
if
(
conf_pass
)
{
CnvPdfObj
o1
=
CnvPdfObj
(
this
,
pdf_eObjType_Page
,
v_pages
.
size
()
+
1
);
v_pages
.
push_back
(
o1
);
CnvPdfObj
o2
=
CnvPdfObj
(
this
,
pdf_eObjType_Content
,
v_content
.
size
()
+
1
);
v_content
.
push_back
(
o2
);
}
if
(
(
int
)
v_content
.
size
()
>
page_number
[
cf
]
-
1
)
v_content
[
page_number
[
cf
]
-
1
].
print_begin
();
page_number
[
cf
]
++
;
y
=
pdf_cPageHeight
-
pdf_cTopMargin
;
}
void
CnvToPdf
::
print_content
()
{
int
size
=
content
.
tab
.
size
();
int
level
=
0
;
int
prev
[
10
]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
int
current
=
v_outline
.
size
();
int
root
=
1
;
int
parent
[
4
]
=
{
0
,
0
,
0
,
0
};
int
offset
=
current
;
if
(
!
current
)
return
;
v_outline
[
root
].
first
=
current
;
v_outline
[
root
].
last
=
current
+
size
-
1
;
v_outline
[
root
].
count
=
size
;
parent
[
level
]
=
root
;
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
level
=
content
.
tab
[
i
].
header_level
;
if
(
level
<
0
)
level
=
0
;
CnvPdfObj
o1
=
CnvPdfObj
(
this
,
pdf_eObjType_OutlineO
,
current
+
1
);
strcpy
(
o1
.
text
,
content
.
tab
[
i
].
text
);
o1
.
parent
=
parent
[
level
];
if
(
parent
[
level
]
!=
root
)
{
v_outline
[
parent
[
level
]].
last
=
current
;
v_outline
[
parent
[
level
]].
count
++
;
}
if
(
i
!=
size
-
1
)
{
if
(
content
.
tab
[
i
+
1
].
header_level
>
content
.
tab
[
i
].
header_level
)
{
parent
[
level
+
1
]
=
current
;
o1
.
first
=
current
+
1
;
}
}
if
(
prev
[
level
])
{
o1
.
prev
=
prev
[
level
];
v_outline
[
o1
.
prev
].
next
=
current
;
}
o1
.
dest
=
size
+
offset
+
content
.
tab
[
i
].
page_number
;
prev
[
level
]
=
current
;
v_outline
.
push_back
(
o1
);
current
++
;
if
(
i
!=
size
-
1
)
{
int
next_level
=
content
.
tab
[
i
+
1
].
header_level
;
if
(
next_level
<
0
)
next_level
=
0
;
if
(
level
>
next_level
)
{
for
(
int
j
=
next_level
+
1
;
j
<=
level
;
j
++
)
prev
[
j
]
=
0
;
}
}
}
#if 0
ci = pdf_eId_Content;
x = pdf_cLeftMargin;
y = pdf_cPageHeight - pdf_cTopMargin;
print_pagebreak( 0);
print_text( Lng::translate("Contents"), style[ci].h1);
for ( int i = 0; i < (int)content.tab.size(); i++) {
char page_str[20];
CnvStyle *cstyle = &style[ci].boldtext;
fp[cf] <<
"gsave" << endl <<
"[1 3] 0 setdash" << endl;
sprintf( page_str, "%d", content.tab[i].page_number);
print_text( content.tab[i].header_number, *cstyle);
x = pdf_cLeftMargin + 30 + content.tab[i].header_level * 5;
y += cstyle->top_offset + cstyle->bottom_offset;
print_text( content.tab[i].text, *cstyle, pdf_mPrintMode_Start | pdf_mPrintMode_FixX);
x = pdf_cLeftMargin + 340;
fp[cf] <<
x << " " << y + cstyle->bottom_offset << " lineto" << endl <<
x << " " << y + cstyle->bottom_offset << " moveto" << endl <<
"closepath" << endl <<
"stroke" << endl <<
"grestore" << endl;
print_text( page_str, *cstyle, pdf_mPrintMode_KeepY | pdf_mPrintMode_FixX);
}
print_pagebreak(0);
#endif
}
CnvToPdf
::~
CnvToPdf
()
{
}
void
CnvToPdf
::
close
()
{
cf
=
pdf_eFile_Body
;
print_pagebreak
(
1
);
// print_content();
for
(
int
i
=
0
;
i
<
(
int
)
v_font
.
size
();
i
++
)
{
v_font
[
i
].
print_begin
();
v_font
[
i
].
print_end
();
}
for
(
int
i
=
0
;
i
<
(
int
)
v_resource
.
size
();
i
++
)
{
v_resource
[
i
].
print_begin
();
v_resource
[
i
].
print_end
();
}
for
(
int
i
=
0
;
i
<
(
int
)
v_image
.
size
();
i
++
)
{
v_image
[
i
].
print_begin
();
v_image
[
i
].
print_end
();
}
xref_offset
=
fp
[
cf
].
tellp
();
fp
[
cf
]
<<
endl
<<
"xref"
<<
endl
<<
"0 "
<<
v_outline
.
size
()
+
v_pages
.
size
()
+
v_content
.
size
()
+
v_font
.
size
()
+
v_resource
.
size
()
+
v_image
.
size
()
+
1
<<
endl
<<
"0000000000 65535 f "
<<
endl
;
for
(
int
i
=
0
;
i
<
(
int
)
v_outline
.
size
();
i
++
)
{
fp
[
cf
].
fill
(
'0'
);
fp
[
cf
].
width
(
10
);
fp
[
cf
]
<<
v_outline
[
i
].
offset
<<
" 00000 n "
<<
endl
;
}
for
(
int
i
=
0
;
i
<
(
int
)
v_pages
.
size
();
i
++
)
{
fp
[
cf
].
fill
(
'0'
);
fp
[
cf
].
width
(
10
);
fp
[
cf
]
<<
v_pages
[
i
].
offset
<<
" 00000 n "
<<
endl
;
}
for
(
int
i
=
0
;
i
<
(
int
)
v_content
.
size
();
i
++
)
{
fp
[
cf
].
fill
(
'0'
);
fp
[
cf
].
width
(
10
);
fp
[
cf
]
<<
v_content
[
i
].
offset
<<
" 00000 n "
<<
endl
;
}
for
(
int
i
=
0
;
i
<
(
int
)
v_font
.
size
();
i
++
)
{
fp
[
cf
].
fill
(
'0'
);
fp
[
cf
].
width
(
10
);
fp
[
cf
]
<<
v_font
[
i
].
offset
-
start_offset
<<
" 00000 n "
<<
endl
;
}
for
(
int
i
=
0
;
i
<
(
int
)
v_resource
.
size
();
i
++
)
{
fp
[
cf
].
fill
(
'0'
);
fp
[
cf
].
width
(
10
);
fp
[
cf
]
<<
v_resource
[
i
].
offset
-
start_offset
<<
" 00000 n "
<<
endl
;
}
for
(
int
i
=
0
;
i
<
(
int
)
v_image
.
size
();
i
++
)
{
fp
[
cf
].
fill
(
'0'
);
fp
[
cf
].
width
(
10
);
fp
[
cf
]
<<
v_image
[
i
].
offset
-
start_offset
<<
" 00000 n "
<<
endl
;
}
fp
[
cf
]
<<
endl
<<
"trailer"
<<
endl
<<
" << /Size "
<<
v_outline
.
size
()
+
v_pages
.
size
()
+
v_content
.
size
()
+
v_font
.
size
()
<<
endl
<<
" /Root 1 0 R"
<<
endl
<<
" >>"
<<
endl
<<
"startxref"
<<
endl
<<
xref_offset
-
start_offset
<<
endl
<<
"%%EOF"
<<
endl
;
fp
[
pdf_eFile_Body
].
close
();
}
#if 0
static void image_pixel( void *userdata, ofstream& fp, unsigned char *rgb)
{
unsigned char transp[3] = {255,0,255};
int grey;
if ( *rgb == transp[0] && *(rgb+1) == transp[1] && *(rgb+2) == transp[2])
grey = 255;
else
grey = (int) ((0.0 + *rgb + *(rgb+1) + *(rgb+2)) / 3 + 0.5);
fp << (unsigned char)grey;
}
#endif
void
CnvToPdf
::
print_horizontal_line
()
{
y
-=
3
;
fp
[
cf
]
<<
" 1 w"
<<
endl
<<
" "
<<
pdf_cLeftMargin
-
50
<<
" "
<<
y
<<
" m"
<<
endl
<<
" "
<<
pdf_cPageWidth
<<
" "
<<
y
<<
" l"
<<
endl
<<
" S"
<<
endl
;
y
-=
3
;
}
int
CnvToPdf
::
print_image_inline
(
char
*
filename
)
{
#if 0
cnv_tImImage image;
cnv_tPixmap pixmap;
pwr_tFileName fname;
int sts;
int width, height;
double scalex = 0.71;
double scaley = 0.78;
x = pdf_cLeftMargin;
// Try $pwr_doc/help/
strcpy( fname, "$pwr_doc/help/");
strcat( fname, filename);
dcli_translate_filename( fname, fname);
sts = cnv_get_image( fname, &image, &pixmap);
if ( EVEN(sts)) {
// Try $pwr_exe
strcpy( fname, "$pwr_exe/");
strcat( fname, filename);
dcli_translate_filename( fname, fname);
sts = cnv_get_image( fname, &image, &pixmap);
if ( EVEN(sts)) {
// Try $pwrp_exe
strcpy( fname, "$pwrp_exe/");
strcat( fname, filename);
dcli_translate_filename( fname, fname);
sts = cnv_get_image( fname, &image, &pixmap);
if ( EVEN(sts)) return 0;
}
}
width = cnv_image_width( image);
height = cnv_image_height( image);
if ( width * scalex > pdf_cPageWidth - pdf_cLeftMargin) {
x = pdf_cPageWidth - width * scalex;
if ( x < 50) {
double scale_factor = (pdf_cPageWidth - 50) / (width * scalex);
x = 50;
scalex = scalex * scale_factor;
scaley = scaley * scale_factor;
}
}
if ( y - height * scaley + 20 < pdf_cBottomMargin)
print_pagebreak( 0);
fp[cf] <<
" q" << endl <<
scalex * width << " 0 0 " << scaley * height << " " << x << " " << y - scaley * height << " cm" << endl <<
" BI" << endl <<
" /W " << width << endl <<
" /H " << height << endl <<
" /CS /G" << endl <<
" /BPC 8" << endl <<
#if 0
" /F /AHx" << endl <<
#endif
" ID" << endl;
cnv_image_pixel_iter( image, image_pixel, 0, fp[cf]);
fp[cf] << endl <<
"EI" << endl <<
" Q" << endl;
fp[cf].flags( ((fp[cf].flags() & ~ios_base::hex) & ~ios_base::uppercase) | ios_base::dec);
cnv_free_image( image, pixmap);
y -= height * scaley;
#endif
return
1
;
}
int
CnvToPdf
::
print_image
(
char
*
filename
)
{
#if 0
cnv_tImImage image;
cnv_tPixmap pixmap;
pwr_tFileName fname;
int sts;
int width, height;
double scalex = 0.71;
double scaley = 0.78;
im_cnt++;
x = pdf_cLeftMargin;
// Try $pwr_doc/help/
strcpy( fname, "$pwr_doc/help/");
strcat( fname, filename);
dcli_translate_filename( fname, fname);
sts = cnv_get_image( fname, &image, &pixmap);
if ( EVEN(sts)) {
// Try $pwr_exe
strcpy( fname, "$pwr_exe/");
strcat( fname, filename);
dcli_translate_filename( fname, fname);
sts = cnv_get_image( fname, &image, &pixmap);
if ( EVEN(sts)) {
// Try $pwrp_exe
strcpy( fname, "$pwrp_exe/");
strcat( fname, filename);
dcli_translate_filename( fname, fname);
sts = cnv_get_image( fname, &image, &pixmap);
if ( EVEN(sts)) return 0;
}
}
width = cnv_image_width( image);
height = cnv_image_height( image);
if ( width * scalex > pdf_cPageWidth - pdf_cLeftMargin) {
x = pdf_cPageWidth - width * scalex;
if ( x < 50) {
double scale_factor = (pdf_cPageWidth - 50) / (width * scalex);
x = 50;
scalex = scalex * scale_factor;
scaley = scaley * scale_factor;
}
}
if ( y - height * scaley + 20 < pdf_cBottomMargin)
print_pagebreak( 0);
fp[cf] <<
" q" << endl <<
" " << scalex * width << " 0 0 " << scaley * height << " " << x << " " << y - scaley * height << " cm" << endl <<
" /Im" << im_cnt << " Do" << endl <<
" Q" << endl;
if ( conf_pass) {
if ( v_pages[v_pages.size()-1].resource == -1) {
v_pages[v_pages.size()-1].resource = v_resource.size();
CnvPdfObj o1 = CnvPdfObj( this, pdf_eObjType_Resource, v_resource.size()+1);
v_resource.push_back( o1);
}
v_resource[v_resource.size()-1].xobject[v_resource[v_resource.size()-1].xobject_cnt] =
v_image.size();
v_resource[v_resource.size()-1].xobject_cnt++;
CnvPdfObj o2 = CnvPdfObj( this, pdf_eObjType_Image, v_image.size()+1);
strcpy( o2.text, filename);
v_image.push_back( o2);
}
cnv_free_image( image, pixmap);
y -= height * scaley;
#endif
return
1
;
}
void
CnvToPdf
::
set_pageheader
(
char
*
text
)
{
strcpy
(
previous_chapter
,
current_chapter
);
strcpy
(
current_chapter
,
text
);
}
void
CnvToPdf
::
print_h1
(
char
*
text
,
int
hlevel
,
char
*
subject
)
{
char
hnum
[
40
];
if
(
ci
==
pdf_eId_Chapter
)
{
set_pageheader
(
text
);
}
if
(
style
[
ci
].
h1
.
display_number
)
{
if
(
hlevel
<
0
)
hlevel
=
0
;
if
(
hlevel
>
pdf_cMaxLevel
-
1
)
hlevel
=
pdf_cMaxLevel
-
1
;
header_number
[
hlevel
]
++
;
switch
(
hlevel
)
{
case
0
:
sprintf
(
hnum
,
"%d"
,
header_number
[
0
]);
break
;
case
1
:
sprintf
(
hnum
,
"%d.%d"
,
header_number
[
0
],
header_number
[
1
]);
break
;
case
2
:
sprintf
(
hnum
,
"%d.%d.%d"
,
header_number
[
0
],
header_number
[
1
],
header_number
[
2
]);
break
;
case
3
:
sprintf
(
hnum
,
"%d.%d.%d.%d"
,
header_number
[
0
],
header_number
[
1
],
header_number
[
2
],
header_number
[
3
]);
break
;
default:
;
}
x
=
pdf_cLeftMargin
-
50
;
print_text
(
hnum
,
style
[
ci
].
h1
,
pdf_mPrintMode_Pos
|
pdf_mPrintMode_FixX
);
double
x0
=
x
+
12.0
*
(
strlen
(
hnum
)
+
1
)
*
style
[
ci
].
h1
.
font_size
/
24
;
x
=
pdf_cLeftMargin
;
if
(
x0
>
x
)
x
=
x0
;
print_text
(
text
,
style
[
ci
].
h1
,
pdf_mPrintMode_KeepY
|
pdf_mPrintMode_FixX
);
}
else
print_text
(
text
,
style
[
ci
].
h1
);
if
(
conf_pass
&&
!
(
ci
==
pdf_eId_TitlePage
||
ci
==
pdf_eId_InfoPage
))
{
CnvContentElem
cnt
;
cnt
.
page_number
=
page_number
[
cf
];
cnt
.
header_level
=
hlevel
;
strcpy
(
cnt
.
header_number
,
hnum
);
strcpy
(
cnt
.
text
,
text
);
strcpy
(
cnt
.
subject
,
subject
);
content
.
add
(
cnt
);
}
strcpy
(
previous_chapter
,
current_chapter
);
}
void
CnvToPdf
::
print_h2
(
char
*
text
)
{
print_text
(
text
,
style
[
ci
].
h2
);
}
void
CnvToPdf
::
print_h3
(
char
*
text
)
{
print_text
(
text
,
style
[
ci
].
h3
);
}
void
CnvToPdf
::
open
()
{
y
=
pdf_cPageHeight
-
pdf_cTopMargin
;
im_cnt
=
0
;
if
(
conf_pass
)
{
fp
[
pdf_eFile_Body
].
open
(
filename
[
pdf_eFile_Body
]);
fp
[
pdf_eFile_Body
]
<<
setiosflags
(
ios
::
fixed
)
<<
setprecision
(
6
);
start_offset
=
fp
[
pdf_eFile_Body
].
tellp
();
}
else
{
print_content
();
conf_pass
=
true
;
page_number
[
cf
]
=
v_content
.
size
()
+
1
;
print_pagebreak
(
1
);
conf_pass
=
false
;
for
(
int
i
=
0
;
i
<
(
int
)
v_image
.
size
();
i
++
)
{
v_image
[
i
].
print_begin
();
v_image
[
i
].
print_end
();
}
// if ( v_content.size() > 0 && v_content[v_content.size()-1].length == 0)
// v_content[v_content.size()-1].length = (int) fp[pdf_eFile_Body].tellp() -
// v_content[v_content.size()-1].start;
fp
[
pdf_eFile_Body
].
seekp
(
start_offset
);
strcpy
(
previous_chapter
,
""
);
strcpy
(
current_chapter
,
""
);
}
cf
=
pdf_eFile_Body
;
page_number
[
cf
]
=
0
;
if
(
conf_pass
)
{
CnvPdfObj
o1
=
CnvPdfObj
(
this
,
pdf_eObjType_Catalog
,
v_outline
.
size
()
+
1
);
v_outline
.
push_back
(
o1
);
CnvPdfObj
o2
=
CnvPdfObj
(
this
,
pdf_eObjType_Outline
,
v_outline
.
size
()
+
1
);
v_outline
.
push_back
(
o2
);
CnvPdfObj
o3
=
CnvPdfObj
(
this
,
pdf_eObjType_Pages
,
v_pages
.
size
()
+
1
);
v_pages
.
push_back
(
o3
);
CnvPdfObj
o4
=
CnvPdfObj
(
this
,
pdf_eObjType_Process
,
v_font
.
size
()
+
1
);
v_font
.
push_back
(
o4
);
CnvPdfObj
o5
=
CnvPdfObj
(
this
,
pdf_eObjType_Font
,
v_font
.
size
()
+
1
);
strcpy
(
o5
.
fontname
,
"Helvetica"
);
v_font
.
push_back
(
o5
);
CnvPdfObj
o6
=
CnvPdfObj
(
this
,
pdf_eObjType_Font
,
v_font
.
size
()
+
1
);
strcpy
(
o6
.
fontname
,
"Helvetica-Bold"
);
v_font
.
push_back
(
o6
);
CnvPdfObj
o7
=
CnvPdfObj
(
this
,
pdf_eObjType_Font
,
v_font
.
size
()
+
1
);
strcpy
(
o7
.
fontname
,
"Helvetica-Oblique"
);
v_font
.
push_back
(
o7
);
CnvPdfObj
o8
=
CnvPdfObj
(
this
,
pdf_eObjType_Font
,
v_font
.
size
()
+
1
);
strcpy
(
o8
.
fontname
,
"TimesNewRoman"
);
v_font
.
push_back
(
o8
);
CnvPdfObj
o9
=
CnvPdfObj
(
this
,
pdf_eObjType_Font
,
v_font
.
size
()
+
1
);
strcpy
(
o9
.
fontname
,
"TimesNewRoman,Bold"
);
v_font
.
push_back
(
o9
);
CnvPdfObj
o10
=
CnvPdfObj
(
this
,
pdf_eObjType_Font
,
v_font
.
size
()
+
1
);
strcpy
(
o10
.
fontname
,
"Courier"
);
v_font
.
push_back
(
o10
);
}
fp
[
cf
]
<<
pdf_cHead
<<
endl
;
for
(
int
i
=
0
;
i
<
(
int
)
v_outline
.
size
();
i
++
)
{
v_outline
[
i
].
print_begin
();
v_outline
[
i
].
print_end
();
}
for
(
int
i
=
0
;
i
<
(
int
)
v_pages
.
size
();
i
++
)
{
v_pages
[
i
].
print_begin
();
v_pages
[
i
].
print_end
();
}
print_pagebreak
(
0
);
for
(
int
i
=
1
;
i
<
pdf_cMaxLevel
;
i
++
)
header_number
[
i
]
=
0
;
}
void
CnvToPdf
::
incr_headerlevel
()
{
ci
++
;
if
(
ci
>
pdf_eId_TopicL3
)
ci
=
pdf_eId_TopicL3
;
if
(
ci
<
pdf_eId_TopicL1
)
ci
=
pdf_eId_TopicL1
;
header_number
[
ci
-
(
int
)
pdf_eId_Chapter
]
=
0
;
}
void
CnvToPdf
::
decr_headerlevel
()
{
ci
--
;
if
(
ci
<
pdf_eId_TopicL1
)
ci
=
pdf_eId_TopicL1
;
}
void
CnvToPdf
::
reset_headernumbers
(
int
level
)
{
for
(
int
i
=
level
;
i
<
pdf_cMaxLevel
;
i
++
)
header_number
[
i
]
=
0
;
}
char
*
CnvToPdf
::
fontname
(
CnvStyle
&
style
)
{
static
char
str
[
80
];
char
name
[
80
];
strcpy
(
name
,
style
.
font
.
c_str
());
if
(
strncmp
(
name
,
"Helvetica-Bold"
,
14
)
==
0
)
strcpy
(
str
,
"/F2"
);
else
if
(
strncmp
(
name
,
"Helvetica-Oblique"
,
17
)
==
0
)
strcpy
(
str
,
"/F3"
);
else
if
(
strncmp
(
name
,
"Helvetica"
,
9
)
==
0
)
strcpy
(
str
,
"/F1"
);
else
if
(
strncmp
(
name
,
"TimesNewRoman-Bold"
,
18
)
==
0
)
strcpy
(
str
,
"/F5"
);
else
if
(
strncmp
(
name
,
"TimesNewRoman"
,
13
)
==
0
)
strcpy
(
str
,
"/F4"
);
else
if
(
strncmp
(
name
,
"Courier"
,
7
)
==
0
)
strcpy
(
str
,
"/F6"
);
else
strcpy
(
str
,
"/F1"
);
return
str
;
}
xtt/lib/flow/src/flow_topdf.h
0 → 100644
View file @
f5d29d96
/*
* Proview $Id: flow_topdf.h,v 1.1 2007-09-25 14:23:51 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef cnv_topdf_h
#define cnv_topdf_h
/* cnv_topdf.h -- Postscript output */
using
namespace
std
;
#include <iostream.h>
#include <vector.h>
#include <string>
#include "pwr.h"
//#include "cnv_style.h"
//#include "cnv_content.h"
typedef
enum
{
cnv_eAlignment_Left
,
cnv_eAlignment_Center
}
cnv_eAlignment
;
class
CnvStyle
{
public:
CnvStyle
()
{}
CnvStyle
(
string
s_font
,
int
s_font_size
,
int
s_indentation
,
int
s_top_offset
,
int
s_bottom_offset
,
int
s_alignment
,
int
s_pagebreak
,
int
s_sidebreak
,
int
s_display_number
)
:
font
(
s_font
),
font_size
(
s_font_size
),
indentation
(
s_indentation
),
top_offset
(
s_top_offset
),
bottom_offset
(
s_bottom_offset
),
alignment
(
s_alignment
),
pagebreak
(
s_pagebreak
),
sidebreak
(
s_sidebreak
),
display_number
(
s_display_number
)
{}
string
font
;
int
font_size
;
int
indentation
;
int
top_offset
;
int
bottom_offset
;
int
alignment
;
int
pagebreak
;
int
sidebreak
;
int
display_number
;
};
class
CnvIdStyle
{
public:
CnvIdStyle
()
{
h1
=
CnvStyle
(
"Helvetica-Bold-ISOLatin1"
,
14
,
0
,
30
,
25
,
cnv_eAlignment_Left
,
0
,
0
,
1
);
h2
=
CnvStyle
(
"Helvetica-Bold-ISOLatin1"
,
12
,
0
,
25
,
20
,
cnv_eAlignment_Left
,
0
,
0
,
1
);
h3
=
CnvStyle
(
"Helvetica-Bold-ISOLatin1"
,
10
,
0
,
15
,
10
,
cnv_eAlignment_Left
,
0
,
0
,
1
);
text
=
CnvStyle
(
"Helvetica-ISOLatin1"
,
10
,
0
,
11
,
2
,
cnv_eAlignment_Left
,
0
,
0
,
0
);
boldtext
=
CnvStyle
(
"Helvetica-Bold-ISOLatin1"
,
10
,
0
,
11
,
2
,
cnv_eAlignment_Left
,
0
,
0
,
0
);
link
=
CnvStyle
(
"Helvetica-Oblique-ISOLatin1"
,
8
,
0
,
11
,
2
,
cnv_eAlignment_Left
,
0
,
0
,
0
);
image
=
CnvStyle
(
"Helvetica-Oblique-ISOLatin1"
,
10
,
0
,
10
,
0
,
cnv_eAlignment_Left
,
0
,
0
,
0
);
code
=
CnvStyle
(
"Courier-ISOLatin1"
,
10
,
0
,
11
,
2
,
cnv_eAlignment_Left
,
0
,
0
,
0
);
}
CnvStyle
h1
;
CnvStyle
h2
;
CnvStyle
h3
;
CnvStyle
text
;
CnvStyle
boldtext
;
CnvStyle
link
;
CnvStyle
image
;
CnvStyle
code
;
};
class
CnvContentElem
{
public:
CnvContentElem
()
:
page_number
(
0
),
header_level
(
0
)
{
strcpy
(
text
,
""
);
strcpy
(
subject
,
""
);}
int
page_number
;
int
header_level
;
char
header_number
[
40
];
char
subject
[
80
];
char
text
[
80
];
};
class
CnvContent
{
public:
CnvContent
()
{}
vector
<
CnvContentElem
>
tab
;
void
add
(
CnvContentElem
&
elem
);
int
find_link
(
char
*
subject
,
char
*
text
,
int
*
page
);
};
#define pdf_cMaxLevel 4
#define pdf_cPageHeight 790
#define pdf_cPageWidth 535
#define pdf_cPageNumX (pdf_cPageWidth - 10)
#define pdf_cPageNumY (pdf_cPageHeight - 13)
#define pdf_cLeftMargin 100
#define pdf_cTopMargin 100
#define pdf_cBottomMargin 50
#define pdf_cCellSize 110
#define pdf_cTmpFile "/tmp/ptmp.ps"
typedef
enum
{
pdf_mPrintMode_Pos
=
1
<<
0
,
pdf_mPrintMode_Start
=
1
<<
1
,
pdf_mPrintMode_Continue
=
1
<<
2
,
pdf_mPrintMode_End
=
1
<<
3
,
pdf_mPrintMode_KeepY
=
1
<<
4
,
pdf_mPrintMode_FixX
=
1
<<
5
}
pdf_mPrintMode
;
typedef
enum
{
pdf_eFile_Body
,
pdf_eFile__
}
pdf_eFile
;
typedef
enum
{
pdf_eId_TitlePage
,
pdf_eId_InfoPage
,
pdf_eId_Content
,
pdf_eId_Chapter
,
pdf_eId_TopicL1
,
pdf_eId_TopicL2
,
pdf_eId_TopicL3
,
pdf_eId_Function
,
pdf_eId_Class
,
pdf_eId__
}
pdf_eId
;
typedef
enum
{
pdf_eObjType_Catalog
,
pdf_eObjType_Page
,
pdf_eObjType_Pages
,
pdf_eObjType_Outline
,
pdf_eObjType_OutlineO
,
pdf_eObjType_Content
,
pdf_eObjType_Process
,
pdf_eObjType_Font
,
pdf_eObjType_Resource
,
pdf_eObjType_Image
}
pdf_eObjType
;
class
CnvToPdf
;
class
CnvPdfObj
{
public:
CnvPdfObj
(
CnvToPdf
*
otopdf
,
pdf_eObjType
otype
,
int
onumber
)
:
topdf
(
otopdf
),
type
(
otype
),
number
(
onumber
),
length
(
0
),
offset
(
0
),
start
(
0
),
parent
(
0
),
first
(
0
),
last
(
0
),
next
(
0
),
prev
(
0
),
dest
(
0
),
count
(
0
),
resource
(
-
1
),
xobject_cnt
(
0
)
{
strcpy
(
fontname
,
""
);
strcpy
(
text
,
""
);}
void
print_begin
();
void
print_end
();
int
print_image
();
CnvToPdf
*
topdf
;
pdf_eObjType
type
;
int
number
;
int
length
;
int
offset
;
int
start
;
char
fontname
[
80
];
int
parent
;
int
first
;
int
last
;
int
next
;
int
prev
;
int
dest
;
int
count
;
char
text
[
200
];
int
resource
;
int
xobject_cnt
;
int
xobject
[
40
];
};
class
CnvToPdf
{
public:
CnvToPdf
()
:
cf
(
0
),
ci
(
0
),
prev_ci
(
0
),
conf_pass
(
false
),
xref_offset
(
0
),
im_cnt
(
0
),
use_outlines
(
1
)
{
for
(
int
i
=
0
;
i
<
pdf_cMaxLevel
;
i
++
)
header_number
[
i
]
=
0
;
for
(
int
i
=
0
;
i
<
pdf_eFile__
;
i
++
)
page_number
[
i
]
=
0
;
strcpy
(
previous_chapter
,
""
);
strcpy
(
current_chapter
,
""
);
style
[
pdf_eId_TitlePage
].
h1
=
CnvStyle
(
"Helvetica-Bold-ISOLatin1"
,
35
,
0
,
100
,
20
,
cnv_eAlignment_Center
,
0
,
0
,
0
);
style
[
pdf_eId_TitlePage
].
h2
=
CnvStyle
(
"Helvetica-Bold-ISOLatin1"
,
25
,
0
,
50
,
20
,
cnv_eAlignment_Center
,
0
,
0
,
0
);
style
[
pdf_eId_TitlePage
].
h3
=
CnvStyle
(
"Helvetica-Bold-ISOLatin1"
,
15
,
0
,
25
,
10
,
cnv_eAlignment_Center
,
0
,
0
,
0
);
style
[
pdf_eId_TitlePage
].
text
=
CnvStyle
(
"Helvetica-ISOLatin1"
,
8
,
0
,
9
,
1
,
cnv_eAlignment_Center
,
0
,
0
,
0
);
style
[
pdf_eId_TitlePage
].
boldtext
=
CnvStyle
(
"Helvetica-Bold-ISOLatin1"
,
8
,
0
,
9
,
1
,
cnv_eAlignment_Center
,
0
,
0
,
0
);
style
[
pdf_eId_InfoPage
].
h1
=
CnvStyle
(
"Helvetica-Bold-ISOLatin1"
,
24
,
0
,
100
,
20
,
cnv_eAlignment_Left
,
0
,
0
,
0
);
style
[
pdf_eId_Chapter
].
h1
=
CnvStyle
(
"Helvetica-Bold-ISOLatin1"
,
24
,
0
,
24
,
40
,
cnv_eAlignment_Left
,
0
,
1
,
1
);
style
[
pdf_eId_TopicL2
].
h1
=
CnvStyle
(
"Helvetica-Bold-ISOLatin1"
,
12
,
0
,
20
,
10
,
cnv_eAlignment_Left
,
0
,
0
,
1
);
style
[
pdf_eId_TopicL2
].
h2
=
CnvStyle
(
"Helvetica-Bold-ISOLatin1"
,
10
,
0
,
16
,
8
,
cnv_eAlignment_Left
,
0
,
0
,
0
);
style
[
pdf_eId_TopicL3
].
h1
=
CnvStyle
(
"Helvetica-Bold-ISOLatin1"
,
10
,
0
,
16
,
8
,
cnv_eAlignment_Left
,
0
,
0
,
1
);
style
[
pdf_eId_TopicL3
].
h2
=
CnvStyle
(
"Helvetica-Bold-ISOLatin1"
,
8
,
0
,
16
,
5
,
cnv_eAlignment_Left
,
0
,
0
,
0
);
style
[
pdf_eId_Function
].
h1
=
CnvStyle
(
"Helvetica-Bold-ISOLatin1"
,
24
,
0
,
24
,
20
,
cnv_eAlignment_Left
,
1
,
0
,
1
);
style
[
pdf_eId_Class
].
h1
=
CnvStyle
(
"Helvetica-Bold-ISOLatin1"
,
24
,
0
,
24
,
20
,
cnv_eAlignment_Left
,
1
,
0
,
1
);
style
[
pdf_eId_Class
].
h2
=
CnvStyle
(
"Helvetica-Bold-ISOLatin1"
,
20
,
0
,
24
,
8
,
cnv_eAlignment_Left
,
0
,
0
,
0
);
style
[
pdf_eId_Class
].
h3
=
CnvStyle
(
"Helvetica-Bold-ISOLatin1"
,
16
,
-
40
,
24
,
6
,
cnv_eAlignment_Left
,
0
,
0
,
0
);
style
[
pdf_eId_Content
].
boldtext
=
CnvStyle
(
"Helvetica-Bold-ISOLatin1"
,
10
,
0
,
11
,
1
,
cnv_eAlignment_Left
,
0
,
0
,
0
);
style
[
pdf_eId_Chapter
].
text
=
CnvStyle
(
"TimesNewRoman-ISOLatin1"
,
10
,
0
,
11
,
1
,
cnv_eAlignment_Left
,
0
,
0
,
0
);
style
[
pdf_eId_TopicL1
].
text
=
CnvStyle
(
"TimesNewRoman-ISOLatin1"
,
10
,
0
,
11
,
1
,
cnv_eAlignment_Left
,
0
,
0
,
0
);
style
[
pdf_eId_TopicL2
].
text
=
CnvStyle
(
"TimesNewRoman-ISOLatin1"
,
10
,
0
,
11
,
1
,
cnv_eAlignment_Left
,
0
,
0
,
0
);
style
[
pdf_eId_TopicL3
].
text
=
CnvStyle
(
"TimesNewRoman-ISOLatin1"
,
10
,
0
,
11
,
1
,
cnv_eAlignment_Left
,
0
,
0
,
0
);
}
~
CnvToPdf
();
void
close
();
void
print_text
(
char
*
text
,
CnvStyle
&
style
,
int
mode
=
pdf_mPrintMode_Pos
);
void
draw_rect
(
double
lw
,
double
x
,
double
y
,
double
w
,
double
h
);
void
draw_arc
(
double
lw
,
double
x
,
double
y
,
double
w
,
double
h
,
int
angel1
,
int
angel2
);
void
draw_line
(
double
lw
,
double
x1
,
double
y1
,
double
x2
,
double
y2
,
int
dashed
,
int
gray
);
void
draw_text
(
double
x
,
double
y
,
char
*
text
,
int
bold
,
double
size
);
void
draw_arrow
(
double
x1
,
double
y1
,
double
x2
,
double
y2
,
double
x3
,
double
y3
,
int
gray
);
void
print_pagebreak
(
int
print_num
);
void
print_content
();
void
print_h1
(
char
*
text
,
int
hlevel
,
char
*
subject
);
void
print_h2
(
char
*
text
);
void
print_h3
(
char
*
text
);
void
print_horizontal_line
();
int
print_image
(
char
*
filename
);
int
print_image_inline
(
char
*
filename
);
void
cnv_text
(
char
*
to
,
char
*
from
);
void
set_confpass
(
bool
conf
)
{
conf_pass
=
conf
;
if
(
!
conf
)
{
// Reset
for
(
int
i
=
0
;
i
<
pdf_cMaxLevel
;
i
++
)
header_number
[
i
]
=
0
;
for
(
int
i
=
0
;
i
<
pdf_eFile__
;
i
++
)
page_number
[
i
]
=
0
;
cf
=
0
;
ci
=
0
;
}
}
void
set_ci
(
int
val
)
{
prev_ci
=
ci
;
ci
=
val
;}
void
set_cf
(
int
val
)
{
cf
=
val
;}
void
set_filename
(
int
idx
,
char
*
name
)
{
strcpy
(
filename
[
idx
],
name
);
}
void
open
();
void
incr_headerlevel
();
void
decr_headerlevel
();
void
reset_headernumbers
(
int
level
);
void
set_pageheader
(
char
*
text
);
void
set_useoutlines
(
int
u
)
{
use_outlines
=
u
;}
char
*
fontname
(
CnvStyle
&
style
);
vector
<
CnvPdfObj
>
v_pages
;
vector
<
CnvPdfObj
>
v_outline
;
vector
<
CnvPdfObj
>
v_content
;
vector
<
CnvPdfObj
>
v_font
;
vector
<
CnvPdfObj
>
v_resource
;
vector
<
CnvPdfObj
>
v_image
;
CnvContent
content
;
CnvIdStyle
style
[
pdf_eId__
];
ofstream
fp
[
pdf_eFile__
];
pwr_tFileName
filename
[
pdf_eFile__
];
int
cf
;
int
ci
;
int
prev_ci
;
double
x
;
double
y
;
int
page_number
[
pdf_eFile__
];
int
header_number
[
pdf_cMaxLevel
];
bool
conf_pass
;
char
current_chapter
[
160
];
char
previous_chapter
[
160
];
int
start_offset
;
int
xref_offset
;
int
im_cnt
;
int
use_outlines
;
};
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment