Skip to content

Commit 9272c59

Browse files
committed
Add svg library, move itextpdf jar to library folder
1 parent 808080e commit 9272c59

File tree

7 files changed

+452
-104
lines changed

7 files changed

+452
-104
lines changed

library/pdf/pdf.rb

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
# @TODO usage
44
class Processing::App
5+
require_relative 'itextpdf-5.5.13.2.jar'
56
java_import Java::ProcessingPdf::PGraphicsPDF
67
end

library/svg/svg.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
# @TODO usage
4+
class Processing::App
5+
require_relative 'batik-all-1.14.jar'
6+
java_import Java::ProcessingSvg::PGraphicsSVG
7+
end

picrate.gemspec

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ Gem::Specification.new do |gem|
2727
gem.files << 'lib/jogl-all-natives-linux-amd64.jar'
2828
gem.files << 'lib/jogl-all-natives-linux-armv6hf.jar'
2929
gem.files << 'lib/jogl-all-natives-linux-aarch64.jar'
30-
gem.files << 'lib/itextpdf-5.5.13.2.jar'
30+
gem.files << 'library/pdf/itextpdf-5.5.13.2.jar'
31+
gem.files << 'library/svg/batik-all-1.14.jar'
3132
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
3233
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
3334
gem.add_development_dependency 'minitest', '~> 5.10'

pom.rb

+15-7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
issue_management 'https://github.com/ruby-processing/PiCrate/issues', 'Github'
2525
# Need to update to jogl 2.4.1 as soon as available, then make a dependency
2626
properties('jogl.version' => '2.3.2',
27+
'batik.version' => '1.14',
2728
'itextpdf.version' => '5.5.13.2',
2829
'jruby.api' => 'http://jruby.org/apidocs/',
2930
'source.directory' => 'src',
@@ -36,6 +37,7 @@
3637
jar 'org.jogamp.jogl:jogl-all:${jogl.version}'
3738
jar 'org.jogamp.gluegen:gluegen-rt-main:${jogl.version}'
3839
jar 'org.processing:video:3.0.2'
40+
jar 'org.apache.xmlgraphics:batik-all:${batik.version}'
3941
jar 'com.itextpdf:itextpdf:${itextpdf.version}'
4042
end
4143

@@ -44,13 +46,19 @@
4446
plugin :dependency, '3.1.2' do
4547
execute_goals( id: 'default-cli',
4648
artifactItems:[
47-
{ groupId: 'com.itextpdf',
48-
artifactId: 'itextpdf',
49-
version: '${itextpdf.version}',
50-
type: 'jar',
51-
outputDirectory: '${picrate.basedir}/lib'
52-
}
53-
]
49+
{ groupId: 'com.itextpdf',
50+
artifactId: 'itextpdf',
51+
version: '${itextpdf.version}',
52+
type: 'jar',
53+
outputDirectory: '${propane.basedir}/library/pdf'
54+
},
55+
{ groupId: 'org.apache.xmlgraphics',
56+
artifactId: 'batik-all',
57+
version: '${batik.version}',
58+
type: 'jar',
59+
outputDirectory: '${propane.basedir}/library/svg'
60+
}
61+
]
5462
)
5563
end
5664
plugin(:compiler, '3.8.1',

pom.xml

+14-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ DO NOT MODIFY - GENERATED CODE
6464
<url>https://github.com/ruby-processing/PiCrate/issues</url>
6565
</issueManagement>
6666
<properties>
67+
<batik.version>1.14</batik.version>
6768
<itextpdf.version>5.5.13.2</itextpdf.version>
6869
<jogl.version>2.3.2</jogl.version>
6970
<jruby.api>http://jruby.org/apidocs/</jruby.api>
@@ -95,6 +96,11 @@ DO NOT MODIFY - GENERATED CODE
9596
<artifactId>video</artifactId>
9697
<version>3.0.2</version>
9798
</dependency>
99+
<dependency>
100+
<groupId>org.apache.xmlgraphics</groupId>
101+
<artifactId>batik-all</artifactId>
102+
<version>${batik.version}</version>
103+
</dependency>
98104
<dependency>
99105
<groupId>com.itextpdf</groupId>
100106
<artifactId>itextpdf</artifactId>
@@ -140,7 +146,14 @@ DO NOT MODIFY - GENERATED CODE
140146
<artifactId>itextpdf</artifactId>
141147
<version>${itextpdf.version}</version>
142148
<type>jar</type>
143-
<outputDirectory>${picrate.basedir}/lib</outputDirectory>
149+
<outputDirectory>${propane.basedir}/library/pdf</outputDirectory>
150+
</artifactItem>
151+
<artifactItem>
152+
<groupId>org.apache.xmlgraphics</groupId>
153+
<artifactId>batik-all</artifactId>
154+
<version>${batik.version}</version>
155+
<type>jar</type>
156+
<outputDirectory>${propane.basedir}/library/svg</outputDirectory>
144157
</artifactItem>
145158
</artifactItems>
146159
</configuration>

src/main/java/processing/pdf/PGraphicsPDF.java

+35-95
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,8 @@
5252
/**
5353
* Thin wrapper for the iText PDF library that handles writing PDF files. The
5454
* majority of the work in this library is done by
55-
* <a href="http://www.lowagie.com/iText/">iText</a>.
56-
* This is currently using iText 2.1.7.
57-
* The issue is that versions from the 5.x series were slow to handle lots of
58-
* fonts with the DefaultFontMapper. 2.x seemed a little slower than 1.x, but
59-
* 5.x took up to 10 times the time to load, meaning a lag of several seconds
60-
* when starting sketches on a machine that had a good handful of fonts
61-
* installed. (Like, say, anyone in our target audience. Or me.)
55+
* <a href="https://github.com/itext/itextpdf">itextpdf</a>. This is currently using
56+
* itextpdf-5.5.13.2.
6257
*/
6358
public class PGraphicsPDF extends PGraphicsJava2D {
6459

@@ -81,10 +76,6 @@ public class PGraphicsPDF extends PGraphicsJava2D {
8176
static protected DefaultFontMapper mapper;
8277
static protected String[] fontList;
8378

84-
/**
85-
*
86-
* @param path
87-
*/
8879
@Override
8980
public void setPath(String path) {
9081
this.path = path;
@@ -167,12 +158,10 @@ public void beginDraw() {
167158
static protected DefaultFontMapper getMapper() {
168159
if (mapper == null) {
169160
mapper = new DefaultFontMapper();
170-
if (PApplet.platform == PConstants.LINUX) {
171-
checkDir("/usr/share/fonts/", mapper);
172-
checkDir("/usr/local/share/fonts/", mapper);
173-
checkDir(System.getProperty("user.home") + "/.fonts", mapper);
161+
checkDir("/usr/share/fonts/", mapper);
162+
checkDir("/usr/local/share/fonts/", mapper);
163+
checkDir(System.getProperty("user.home") + "/.fonts", mapper);
174164
}
175-
}
176165
return mapper;
177166
}
178167

@@ -186,8 +175,10 @@ static protected void checkDir(String path, DefaultFontMapper mapper) {
186175

187176
/**
188177
* Recursive walk to get all subdirectories for font fun.Patch submitted by
189-
Matthias Breuer.(<a href="http://dev.processing.org/bugs/show_bug.cgi?id=1566">Bug
190-
1566</a>)
178+
* Matthias
179+
* Breuer.(<a href="http://dev.processing.org/bugs/show_bug.cgi?id=1566">Bug
180+
* 1566</a>)
181+
*
191182
* @param folder
192183
* @param mapper
193184
*/
@@ -258,45 +249,6 @@ public boolean displayable() {
258249
return false;
259250
}
260251

261-
/*
262-
protected void finalize() throws Throwable {
263-
System.out.println("calling finalize");
264-
//document.close(); // do this in dispose instead?
265-
}
266-
*/
267-
//////////////////////////////////////////////////////////////
268-
/*
269-
public void endRecord() {
270-
super.endRecord();
271-
dispose();
272-
}
273-
274-
275-
public void endRaw() {
276-
System.out.println("ending raw");
277-
super.endRaw();
278-
System.out.println("disposing");
279-
dispose();
280-
System.out.println("done");
281-
}
282-
*/
283-
//////////////////////////////////////////////////////////////
284-
/*
285-
protected void rectImpl(float x1, float y1, float x2, float y2) {
286-
//rect.setFrame(x1, y1, x2-x1, y2-y1);
287-
//draw_shape(rect);
288-
System.out.println("rect implements");
289-
g2.fillRect((int)x1, (int)y1, (int) (x2-x1), (int) (y2-y1));
290-
}
291-
*
292-
293-
/*
294-
public void clear() {
295-
g2.setColor(Color.red);
296-
g2.fillRect(0, 0, width, height);
297-
}
298-
*/
299-
//////////////////////////////////////////////////////////////
300252
@Override
301253
protected void imageImpl(PImage image,
302254
float x1, float y1, float x2, float y2,
@@ -321,49 +273,36 @@ protected void imageImpl(PImage image,
321273
public void textFont(PFont which) {
322274
super.textFont(which);
323275
checkFont();
324-
// Make sure a native version of the font is available.
325-
// if (textFont.getFont() == null) {
326-
// throw new RuntimeException("Use createFont() instead of loadFont() " +
327-
// "when drawing text using the PDF library.");
328-
// }
329-
// Make sure that this is a font that the PDF library can deal with.
330-
// if ((textMode != SHAPE) && !checkFont(which.getName())) {
331-
// System.err.println("Use PGraphicsPDF.listFonts() to get a list of available fonts.");
332-
// throw new RuntimeException("The font “" + which.getName() + "” cannot be used with PDF Export.");
333-
// }
334276
}
335277

336278
/**
337-
* Change the textMode() to either SHAPE or MODEL.
338-
* This resets all renderer settings, and therefore must be called
279+
* Change the textMode() to either SHAPE or MODEL. This resets all renderer
280+
* settings, and therefore must be called
339281
* <EM>before</EM> any other commands that set the fill() or the textFont()
340282
* or anything. Unlike other renderers, use textMode() directly after the
341283
* size() command.
342284
*/
343-
@Override
344-
public void textMode(int mode) {
345-
if (textMode != mode) {
346-
switch (mode) {
347-
case SHAPE:
348-
textMode = SHAPE;
349-
g2.dispose();
350-
// g2 = content.createGraphicsShapes(width, height);
351-
g2 = createGraphics();
352-
break;
353-
case MODEL:
354-
textMode = MODEL;
355-
g2.dispose();
356-
// g2 = content.createGraphics(width, height, mapper);
357-
g2 = createGraphics();
358-
// g2 = template.createGraphics(width, height, mapper);
359-
break;
360-
case SCREEN:
361-
throw new RuntimeException("textMode(SCREEN) not supported with PDF");
362-
default:
363-
throw new RuntimeException("That textMode() does not exist");
364-
}
365-
}
366-
}
285+
@Override
286+
public void textMode(int mode) {
287+
if (textMode != mode) {
288+
switch (mode) {
289+
case SHAPE:
290+
textMode = SHAPE;
291+
g2.dispose();
292+
g2 = createGraphics();
293+
break;
294+
case MODEL:
295+
textMode = MODEL;
296+
g2.dispose();
297+
g2 = createGraphics();
298+
break;
299+
case SCREEN:
300+
throw new RuntimeException("textMode(SCREEN) not supported with PDF");
301+
default:
302+
throw new RuntimeException("That textMode() does not exist");
303+
}
304+
}
305+
}
367306

368307
@Override
369308
protected void textLineImpl(char buffer[], int start, int stop,
@@ -418,7 +357,6 @@ public void set(int x, int y, PImage image) {
418357
}
419358

420359
//
421-
422360
/**
423361
*
424362
* @param alpha
@@ -516,6 +454,7 @@ public boolean save(String filename) {
516454
* On Linux or any other platform, you'll need to add the directories by
517455
* hand. (If there are actual standards here that we can use as a starting
518456
* point, please file a bug to make a note of it)
457+
*
519458
* @param directory
520459
*/
521460
public void addFonts(String directory) {
@@ -555,7 +494,8 @@ protected void checkFont() {
555494

556495
/**
557496
* List the fonts known to the PDF renderer.This is like PFont.list(),
558-
however not all those fonts are available by default.
497+
* however not all those fonts are available by default.
498+
*
559499
* @return
560500
*/
561501
static public String[] listFonts() {

0 commit comments

Comments
 (0)