Skip to content

Commit fe9e032

Browse files
committed
PDFBOX-4951: add tests, by Volker Kunert; move resources to test for now
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1935881 13f79535-47bb-0310-9956-ffa450edef68
1 parent b4f2153 commit fe9e032

10 files changed

Lines changed: 880 additions & 0 deletions

File tree

Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
Lohit fonts (https://pagure.io/lohit):
2+
3+
Copyright 2011-15 Lohit Fonts Project contributors
4+
5+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
6+
This license is copied below, and is also available with a FAQ at:
7+
http://scripts.sil.org/OFL
8+
9+
10+
-----------------------------------------------------------
11+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
12+
-----------------------------------------------------------
13+
14+
PREAMBLE
15+
The goals of the Open Font License (OFL) are to stimulate worldwide
16+
development of collaborative font projects, to support the font creation
17+
efforts of academic and linguistic communities, and to provide a free and
18+
open framework in which fonts may be shared and improved in partnership
19+
with others.
20+
21+
The OFL allows the licensed fonts to be used, studied, modified and
22+
redistributed freely as long as they are not sold by themselves. The
23+
fonts, including any derivative works, can be bundled, embedded,
24+
redistributed and/or sold with any software provided that any reserved
25+
names are not used by derivative works. The fonts and derivatives,
26+
however, cannot be released under any other type of license. The
27+
requirement for fonts to remain under this license does not apply
28+
to any document created using the fonts or their derivatives.
29+
30+
DEFINITIONS
31+
"Font Software" refers to the set of files released by the Copyright
32+
Holder(s) under this license and clearly marked as such. This may
33+
include source files, build scripts and documentation.
34+
35+
"Reserved Font Name" refers to any names specified as such after the
36+
copyright statement(s).
37+
38+
"Original Version" refers to the collection of Font Software components as
39+
distributed by the Copyright Holder(s).
40+
41+
"Modified Version" refers to any derivative made by adding to, deleting,
42+
or substituting -- in part or in whole -- any of the components of the
43+
Original Version, by changing formats or by porting the Font Software to a
44+
new environment.
45+
46+
"Author" refers to any designer, engineer, programmer, technical
47+
writer or other person who contributed to the Font Software.
48+
49+
PERMISSION & CONDITIONS
50+
Permission is hereby granted, free of charge, to any person obtaining
51+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
52+
redistribute, and sell modified and unmodified copies of the Font
53+
Software, subject to the following conditions:
54+
55+
1) Neither the Font Software nor any of its individual components,
56+
in Original or Modified Versions, may be sold by itself.
57+
58+
2) Original or Modified Versions of the Font Software may be bundled,
59+
redistributed and/or sold with any software, provided that each copy
60+
contains the above copyright notice and this license. These can be
61+
included either as stand-alone text files, human-readable headers or
62+
in the appropriate machine-readable metadata fields within text or
63+
binary files as long as those fields can be easily viewed by the user.
64+
65+
3) No Modified Version of the Font Software may use the Reserved Font
66+
Name(s) unless explicit written permission is granted by the corresponding
67+
Copyright Holder. This restriction only applies to the primary font name as
68+
presented to the users.
69+
70+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
71+
Software shall not be used to promote, endorse or advertise any
72+
Modified Version, except to acknowledge the contribution(s) of the
73+
Copyright Holder(s) and the Author(s) or with their explicit written
74+
permission.
75+
76+
5) The Font Software, modified or unmodified, in part or in whole,
77+
must be distributed entirely under this license, and must not be
78+
distributed under any other license. The requirement for fonts to
79+
remain under this license does not apply to any document created
80+
using the Font Software.
81+
82+
TERMINATION
83+
This license becomes null and void if any of the above conditions are
84+
not met.
85+
86+
DISCLAIMER
87+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
88+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
89+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
90+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
91+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
92+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
93+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
94+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
95+
OTHER DEALINGS IN THE FONT SOFTWARE.
96+
97+
98+
FiraCode font:
99+
100+
Copyright (c) 2014, The Fira Code Project Authors (https://github.com/tonsky/FiraCode)
101+
SIL Open Font License, see above
102+
103+
104+
NotoSans Arabic font:
105+
106+
Copyright 2022 The Noto Project Authors (https://github.com/notofonts/arabic)
107+
SIL Open Font License, see above
108+
109+
110+
Licenses for DejaVu font(s) (see also https://www.apache.org/legal/resolved.html ):
111+
112+
Fonts are (c) Bitstream (see below). DejaVu changes are in public domain.
113+
Glyphs imported from Arev fonts are (c) Tavmjong Bah (see below)
114+
115+
116+
Bitstream Vera Fonts Copyright
117+
------------------------------
118+
119+
Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is
120+
a trademark of Bitstream, Inc.
121+
122+
Permission is hereby granted, free of charge, to any person obtaining a copy
123+
of the fonts accompanying this license ("Fonts") and associated
124+
documentation files (the "Font Software"), to reproduce and distribute the
125+
Font Software, including without limitation the rights to use, copy, merge,
126+
publish, distribute, and/or sell copies of the Font Software, and to permit
127+
persons to whom the Font Software is furnished to do so, subject to the
128+
following conditions:
129+
130+
The above copyright and trademark notices and this permission notice shall
131+
be included in all copies of one or more of the Font Software typefaces.
132+
133+
The Font Software may be modified, altered, or added to, and in particular
134+
the designs of glyphs or characters in the Fonts may be modified and
135+
additional glyphs or characters may be added to the Fonts, only if the fonts
136+
are renamed to names not containing either the words "Bitstream" or the word
137+
"Vera".
138+
139+
This License becomes null and void to the extent applicable to Fonts or Font
140+
Software that has been modified and is distributed under the "Bitstream
141+
Vera" names.
142+
143+
The Font Software may be sold as part of a larger software package but no
144+
copy of one or more of the Font Software typefaces may be sold by itself.
145+
146+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
147+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
148+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
149+
TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME
150+
FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING
151+
ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
152+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
153+
THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE
154+
FONT SOFTWARE.
155+
156+
Except as contained in this notice, the names of Gnome, the Gnome
157+
Foundation, and Bitstream Inc., shall not be used in advertising or
158+
otherwise to promote the sale, use or other dealings in this Font Software
159+
without prior written authorization from the Gnome Foundation or Bitstream
160+
Inc., respectively. For further information, contact: fonts at gnome dot org.
161+
162+
Arev Fonts Copyright
163+
------------------------------
164+
165+
Copyright (c) 2006 by Tavmjong Bah. All Rights Reserved.
166+
167+
Permission is hereby granted, free of charge, to any person obtaining
168+
a copy of the fonts accompanying this license ("Fonts") and
169+
associated documentation files (the "Font Software"), to reproduce
170+
and distribute the modifications to the Bitstream Vera Font Software,
171+
including without limitation the rights to use, copy, merge, publish,
172+
distribute, and/or sell copies of the Font Software, and to permit
173+
persons to whom the Font Software is furnished to do so, subject to
174+
the following conditions:
175+
176+
The above copyright and trademark notices and this permission notice
177+
shall be included in all copies of one or more of the Font Software
178+
typefaces.
179+
180+
The Font Software may be modified, altered, or added to, and in
181+
particular the designs of glyphs or characters in the Fonts may be
182+
modified and additional glyphs or characters may be added to the
183+
Fonts, only if the fonts are renamed to names not containing either
184+
the words "Tavmjong Bah" or the word "Arev".
185+
186+
This License becomes null and void to the extent applicable to Fonts
187+
or Font Software that has been modified and is distributed under the
188+
"Tavmjong Bah Arev" names.
189+
190+
The Font Software may be sold as part of a larger software package but
191+
no copy of one or more of the Font Software typefaces may be sold by
192+
itself.
193+
194+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
195+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
196+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
197+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL
198+
TAVMJONG BAH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
199+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
200+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
201+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
202+
OTHER DEALINGS IN THE FONT SOFTWARE.
203+
204+
Except as contained in this notice, the name of Tavmjong Bah shall not
205+
be used in advertising or otherwise to promote the sale, use or other
206+
dealings in this Font Software without prior written authorization
207+
from Tavmjong Bah. For further information, contact: tavmjong @ free . fr.
208+
209+
TeX Gyre DJV Math
210+
-----------------
211+
Fonts are (c) Bitstream (see below). DejaVu changes are in public domain.
212+
213+
Math extensions done by B. Jackowski, P. Strzelczyk and P. Pianowski
214+
(on behalf of TeX users groups) are in public domain.
215+
216+
Letters imported from Euler Fraktur from AMSfonts are (c) American Mathematical Society (see below).
217+
Bitstream Vera Fonts Copyright
218+
Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera
219+
is a trademark of Bitstream, Inc.
220+
221+
Permission is hereby granted, free of charge, to any person obtaining a copy
222+
of the fonts accompanying this license (“Fonts”) and associated documentation
223+
files (the “Font Software”), to reproduce and distribute the Font Software,
224+
including without limitation the rights to use, copy, merge, publish, distribute,
225+
and/or sell copies of the Font Software, and to permit persons to whom
226+
the Font Software is furnished to do so, subject to the following conditions:
227+
228+
The above copyright and trademark notices and this permission notice shall be
229+
included in all copies of one or more of the Font Software typefaces.
230+
231+
The Font Software may be modified, altered, or added to, and in particular
232+
the designs of glyphs or characters in the Fonts may be modified and additional
233+
glyphs or characters may be added to the Fonts, only if the fonts are renamed
234+
to names not containing either the words “Bitstream” or the word “Vera”.
235+
236+
This License becomes null and void to the extent applicable to Fonts or Font Software
237+
that has been modified and is distributed under the “Bitstream Vera” names.
238+
239+
The Font Software may be sold as part of a larger software package but no copy
240+
of one or more of the Font Software typefaces may be sold by itself.
241+
242+
THE FONT SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
243+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
244+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
245+
TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME FOUNDATION
246+
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL,
247+
SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION
248+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE
249+
THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
250+
Except as contained in this notice, the names of GNOME, the GNOME Foundation,
251+
and Bitstream Inc., shall not be used in advertising or otherwise to promote
252+
the sale, use or other dealings in this Font Software without prior written
253+
authorization from the GNOME Foundation or Bitstream Inc., respectively.
254+
For further information, contact: fonts at gnome dot org.
255+
256+
AMSFonts (v. 2.2) copyright
257+
258+
The PostScript Type 1 implementation of the AMSFonts produced by and
259+
previously distributed by Blue Sky Research and Y&Y, Inc. are now freely
260+
available for general use. This has been accomplished through the cooperation
261+
of a consortium of scientific publishers with Blue Sky Research and Y&Y.
262+
Members of this consortium include:
263+
264+
Elsevier Science IBM Corporation Society for Industrial and Applied
265+
Mathematics (SIAM) Springer-Verlag American Mathematical Society (AMS)
266+
267+
In order to assure the authenticity of these fonts, copyright will be held by
268+
the American Mathematical Society. This is not meant to restrict in any way
269+
the legitimate use of the fonts, such as (but not limited to) electronic
270+
distribution of documents containing these fonts, inclusion of these fonts
271+
into other public domain or commercial font collections or computer
272+
applications, use of the outline data to create derivative fonts and/or
273+
faces, etc. However, the AMS does require that the AMS copyright notice be
274+
removed from any derivative versions of the fonts which have been altered in
275+
any way. In addition, to ensure the fidelity of TeX documents using Computer
276+
Modern fonts, Professor Donald Knuth, creator of the Computer Modern faces,
277+
has requested that any alterations which yield different font metrics be
278+
given a different name.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.pdfbox.glyphlayout;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import java.awt.FontFormatException;
22+
import java.io.IOException;
23+
import java.io.InputStream;
24+
25+
import org.apache.pdfbox.pdmodel.PDDocument;
26+
import org.apache.pdfbox.pdmodel.PDPage;
27+
import org.apache.pdfbox.pdmodel.PDPageContentStream;
28+
import org.apache.pdfbox.pdmodel.font.PDType0Font;
29+
30+
/**
31+
* Examples for bidirectional text with GlyphLayoutProcessorAwt
32+
*
33+
* @author Volker Kunert
34+
*/
35+
public class GlyphLayoutBidiTest
36+
{
37+
public static final String TEXT1 = "نحن الآن في شهر رمضان 1447 هجري";
38+
public static final String TEXT2 = "Guten Tag ";
39+
public static final String TEXT3 = "السلام عليكم";
40+
public static final String TEXT4 = " Good afternoon";
41+
42+
/*
43+
* show one line
44+
*/
45+
private float showLine(PDPageContentStream cs, PDType0Font font, float fontSize,
46+
float x, float y, String text) throws IOException
47+
{
48+
return showLine(cs, new PDType0Font[]{font}, fontSize, x, y, new String[]{text});
49+
}
50+
51+
/*
52+
* show one line
53+
*/
54+
private float showLine(PDPageContentStream cs, PDType0Font[] fonts, float fontSize,
55+
float x, float y, String[] texts) throws IOException
56+
{
57+
cs.beginText();
58+
cs.newLineAtOffset(x, y);
59+
60+
if (fonts.length != texts.length)
61+
{
62+
throw new IllegalArgumentException("Size of fonts and texts is different");
63+
}
64+
for (int i = 0; i < texts.length; i++)
65+
{
66+
cs.setFont(fonts[i], fontSize);
67+
cs.showText(texts[i]);
68+
}
69+
cs.endText();
70+
71+
float height = fonts[0].getBoundingBox().getHeight();
72+
y -= height / 1000f * fontSize;
73+
return y;
74+
}
75+
76+
@Test
77+
void testGlyphLayoutBidi() throws IOException, FontFormatException
78+
{
79+
GlyphLayoutProcessorAwt glyphLayoutProcessorAwt = new GlyphLayoutProcessorAwt();
80+
81+
String outputFilename = "target/GlyphLayoutBidi.pdf";
82+
String arabicPath = "/ttf/NotoSansArabic-Regular.ttf";
83+
String lgcPath = "/ttf/DejaVuSans.ttf";
84+
85+
float fontSize = 12.0f;
86+
87+
try (PDDocument doc = new PDDocument())
88+
{
89+
PDType0Font arabicFont = createPdType0Font(glyphLayoutProcessorAwt, doc, arabicPath);
90+
PDType0Font lgcFont = createPdType0Font(glyphLayoutProcessorAwt, doc, lgcPath);
91+
92+
PDPage page = new PDPage();
93+
doc.addPage(page);
94+
try (PDPageContentStream cs = new PDPageContentStream(doc, page))
95+
{
96+
cs.setGlyphLayoutProcessor(glyphLayoutProcessorAwt);
97+
98+
float x = page.getBBox().getLowerLeftX() + fontSize;
99+
float y = page.getBBox().getUpperRightY() - fontSize;
100+
101+
y = showLine(cs, arabicFont, fontSize, x, y, TEXT1);
102+
showLine(cs, new PDType0Font[]{ lgcFont, arabicFont, lgcFont }, fontSize, x, y, new String[]{ TEXT2, TEXT3, TEXT4 });
103+
}
104+
doc.save(outputFilename);
105+
}
106+
}
107+
108+
/*
109+
* Create the PDType0Font font
110+
*/
111+
private PDType0Font createPdType0Font(GlyphLayoutProcessorAwt glyphLayoutProcessorAwt, PDDocument doc,
112+
String fontPath) throws IOException, FontFormatException
113+
{
114+
InputStream fontStream = this.getClass().getResourceAsStream(fontPath);
115+
return glyphLayoutProcessorAwt.loadFont(doc, fontStream);
116+
}
117+
}

0 commit comments

Comments
 (0)