3 % Copyright
2009-2010 Taco Hoekwater
<taco@@luatex.org
>
5 % This file is part of LuaTeX.
7 % LuaTeX is free software
; you can redistribute it and
/or modify it under
8 % the terms of the GNU General Public License as published by the Free
9 % Software Foundation
; either version
2 of the License
, or
(at your
10 % option
) any later version.
12 % LuaTeX is distributed in the hope that it will be useful
, but WITHOUT
13 % ANY WARRANTY
; without even the implied warranty of MERCHANTABILITY or
14 % FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 % License for more details.
17 % You should have received a copy of the GNU General Public License along
18 % with LuaTeX
; if not
, see
<http
://www.gnu.org
/licenses
/>.
25 void pdf_special
(PDF pdf
, halfword p
)
27 int old_setting
= selector
;
29 selector
= new_string
;
30 show_token_list
(token_link
(write_tokens
(p
)), null
, -1);
31 selector
= old_setting
;
33 pdf_literal
(pdf
, s
, scan_special
, true
);
37 @ To ship out a \TeX\ box to PDF page description we need to implement
38 |hlist_out|
, |vlist_out| and |ship_out|
, which are equivalent to the \TeX'
39 original |hlist_out|
, |vlist_out| and |ship_out| resp. But first we need to
40 declare some procedures needed in |hlist_out| and |vlist_out|.
43 void pdf_out_literal
(PDF pdf
, halfword p
)
45 int old_setting
; /* holds print |selector|
*/
47 pdfstructure
*ps
= pdf-
>pstruct
;
48 if
(pdf_literal_type
(p
) == normal
) {
49 old_setting
= selector
;
50 selector
= new_string
;
51 show_token_list
(token_link
(pdf_literal_data
(p
)), null
, -1);
52 selector
= old_setting
;
54 pdf_literal
(pdf
, s
, pdf_literal_mode
(p
), false
);
57 switch
(pdf_literal_mode
(p
)) {
59 pdf_goto_pagemode
(pdf
);
60 pdf_set_pos
(pdf
, pdf-
>posstruct-
>pos
);
63 pdf_goto_pagemode
(pdf
);
66 pdf_end_string_nl
(pdf
);
70 normal_error
("pdf backend","bad literal mode");
73 lua_pdf_literal
(pdf
, pdf_literal_data
(p
));
77 @ test equality of start of strings
79 static boolean str_in_cstr
(str_number s
, const char
*r
, unsigned i
)
81 const unsigned char
*k
, *l
;
82 if
((unsigned
) str_length
(s
) < i
+ strlen
(r
))
84 k
= (const unsigned char
*) r
;
85 l
= str_string
(s
) + i
;
86 while
((*l
) && (*k)) {
94 void pdf_literal
(PDF pdf
, str_number s
, int literal_mode
, boolean warn
)
98 pool_pointer j
= 0; /* current character code position
, initialized to make the compiler happy
*/
99 pdfstructure
*p
= pdf-
>pstruct
;
100 if
(s
>= STRING_OFFSET
) {
101 /* needed for |out_save|
*/
103 /* the next is obsolete
, in fact
, specials are obsolete in pdf mode
*/
104 if
(literal_mode
== scan_special
) {
105 if
(!(str_in_cstr
(s
, "PDF:", 0) || str_in_cstr
(s
, "pdf:", 0))) {
106 if
(warn
&& ((!(str_in_cstr(s, "SRC:", 0) || str_in_cstr(s, "src:", 0))) || (str_length(s) == 0)))
107 tprint_nl
("Non-PDF special ignored!");
110 j
= j
+ (pool_pointer
) strlen
("PDF:");
111 if
(str_in_cstr
(s
, "direct:", strlen
("PDF:"))) {
112 j
= j
+ (pool_pointer
) strlen
("direct:");
113 literal_mode
= direct_always
;
114 } else if
(str_in_cstr
(s
, "page:", strlen
("PDF:"))) {
115 j
= j
+ (pool_pointer
) strlen
("page:");
116 literal_mode
= direct_page
;
118 literal_mode
= set_origin
;
122 switch
(literal_mode
) {
124 pdf_goto_pagemode
(pdf
);
125 pdf_set_pos
(pdf
, pdf-
>posstruct-
>pos
);
128 pdf_goto_pagemode
(pdf
);
131 pdf_end_string_nl
(pdf
);
135 normal_error
("pdf backend","bad literal mode");
138 if
(s
>= STRING_OFFSET
) {
140 l
= str_length
(s
) - (size_t
) j
;
141 pdf_out_block
(pdf
, (const char
*) (ss
+ j
), l
);