propane 3.9.0-java → 3.10.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/CHANGELOG.md +2 -2
  4. data/README.md +3 -3
  5. data/Rakefile +6 -6
  6. data/lib/java/japplemenubar/JAppleMenuBar.java +88 -0
  7. data/lib/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
  8. data/lib/java/monkstone/ColorUtil.java +127 -0
  9. data/lib/java/monkstone/MathToolModule.java +287 -0
  10. data/lib/java/monkstone/PropaneLibrary.java +46 -0
  11. data/lib/java/monkstone/core/LibraryProxy.java +136 -0
  12. data/lib/java/monkstone/fastmath/DegLutTables.java +111 -0
  13. data/lib/java/monkstone/fastmath/Deglut.java +71 -0
  14. data/lib/java/monkstone/fastmath/package-info.java +6 -0
  15. data/lib/java/monkstone/filechooser/Chooser.java +39 -0
  16. data/{src/main → lib}/java/monkstone/noise/FastTerrain.java +0 -0
  17. data/{src/main → lib}/java/monkstone/noise/Noise.java +0 -0
  18. data/{src/main → lib}/java/monkstone/noise/NoiseGenerator.java +0 -0
  19. data/{src/main → lib}/java/monkstone/noise/NoiseMode.java +0 -0
  20. data/lib/java/monkstone/noise/OpenSimplex2F.java +881 -0
  21. data/lib/java/monkstone/noise/OpenSimplex2S.java +1106 -0
  22. data/{src/main → lib}/java/monkstone/noise/SmoothTerrain.java +0 -0
  23. data/lib/java/monkstone/slider/CustomHorizontalSlider.java +164 -0
  24. data/lib/java/monkstone/slider/CustomVerticalSlider.java +178 -0
  25. data/lib/java/monkstone/slider/SimpleHorizontalSlider.java +145 -0
  26. data/lib/java/monkstone/slider/SimpleSlider.java +166 -0
  27. data/lib/java/monkstone/slider/SimpleVerticalSlider.java +157 -0
  28. data/lib/java/monkstone/slider/Slider.java +61 -0
  29. data/lib/java/monkstone/slider/SliderBar.java +245 -0
  30. data/lib/java/monkstone/slider/SliderGroup.java +56 -0
  31. data/lib/java/monkstone/slider/WheelHandler.java +35 -0
  32. data/lib/java/monkstone/vecmath/GfxRender.java +86 -0
  33. data/lib/java/monkstone/vecmath/JRender.java +56 -0
  34. data/lib/java/monkstone/vecmath/ShapeRender.java +87 -0
  35. data/lib/java/monkstone/vecmath/package-info.java +20 -0
  36. data/lib/java/monkstone/vecmath/vec2/Vec2.java +802 -0
  37. data/lib/java/monkstone/vecmath/vec2/package-info.java +6 -0
  38. data/lib/java/monkstone/vecmath/vec3/Vec3.java +727 -0
  39. data/lib/java/monkstone/vecmath/vec3/package-info.java +6 -0
  40. data/lib/java/monkstone/videoevent/CaptureEvent.java +27 -0
  41. data/lib/java/monkstone/videoevent/MovieEvent.java +32 -0
  42. data/lib/java/monkstone/videoevent/package-info.java +20 -0
  43. data/lib/java/processing/awt/PGraphicsJava2D.java +3040 -0
  44. data/lib/java/processing/awt/PImageAWT.java +377 -0
  45. data/lib/java/processing/awt/PShapeJava2D.java +387 -0
  46. data/lib/java/processing/awt/PSurfaceAWT.java +1581 -0
  47. data/lib/java/processing/awt/ShimAWT.java +581 -0
  48. data/lib/java/processing/core/PApplet.java +15156 -0
  49. data/lib/java/processing/core/PConstants.java +523 -0
  50. data/lib/java/processing/core/PFont.java +1126 -0
  51. data/lib/java/processing/core/PGraphics.java +8600 -0
  52. data/lib/java/processing/core/PImage.java +3377 -0
  53. data/lib/java/processing/core/PMatrix.java +208 -0
  54. data/lib/java/processing/core/PMatrix2D.java +562 -0
  55. data/lib/java/processing/core/PMatrix3D.java +890 -0
  56. data/lib/java/processing/core/PShape.java +3561 -0
  57. data/lib/java/processing/core/PShapeOBJ.java +483 -0
  58. data/lib/java/processing/core/PShapeSVG.java +2016 -0
  59. data/lib/java/processing/core/PStyle.java +63 -0
  60. data/lib/java/processing/core/PSurface.java +198 -0
  61. data/lib/java/processing/core/PSurfaceNone.java +431 -0
  62. data/lib/java/processing/core/PVector.java +1066 -0
  63. data/lib/java/processing/core/ThinkDifferent.java +115 -0
  64. data/lib/java/processing/data/DoubleDict.java +850 -0
  65. data/lib/java/processing/data/DoubleList.java +928 -0
  66. data/lib/java/processing/data/FloatDict.java +847 -0
  67. data/lib/java/processing/data/FloatList.java +936 -0
  68. data/lib/java/processing/data/IntDict.java +807 -0
  69. data/lib/java/processing/data/IntList.java +936 -0
  70. data/lib/java/processing/data/JSONArray.java +1260 -0
  71. data/lib/java/processing/data/JSONObject.java +2282 -0
  72. data/lib/java/processing/data/JSONTokener.java +435 -0
  73. data/lib/java/processing/data/LongDict.java +802 -0
  74. data/lib/java/processing/data/LongList.java +937 -0
  75. data/lib/java/processing/data/Sort.java +46 -0
  76. data/lib/java/processing/data/StringDict.java +613 -0
  77. data/lib/java/processing/data/StringList.java +800 -0
  78. data/lib/java/processing/data/Table.java +4936 -0
  79. data/lib/java/processing/data/TableRow.java +198 -0
  80. data/lib/java/processing/data/XML.java +1156 -0
  81. data/lib/java/processing/dxf/RawDXF.java +404 -0
  82. data/lib/java/processing/event/Event.java +125 -0
  83. data/lib/java/processing/event/KeyEvent.java +70 -0
  84. data/lib/java/processing/event/MouseEvent.java +114 -0
  85. data/lib/java/processing/event/TouchEvent.java +57 -0
  86. data/lib/java/processing/javafx/PGraphicsFX2D.java +32 -0
  87. data/lib/java/processing/javafx/PSurfaceFX.java +173 -0
  88. data/lib/java/processing/net/Client.java +744 -0
  89. data/lib/java/processing/net/Server.java +388 -0
  90. data/lib/java/processing/opengl/FontTexture.java +378 -0
  91. data/lib/java/processing/opengl/FrameBuffer.java +513 -0
  92. data/lib/java/processing/opengl/LinePath.java +627 -0
  93. data/lib/java/processing/opengl/LineStroker.java +681 -0
  94. data/lib/java/processing/opengl/PGL.java +3483 -0
  95. data/lib/java/processing/opengl/PGraphics2D.java +615 -0
  96. data/lib/java/processing/opengl/PGraphics3D.java +281 -0
  97. data/lib/java/processing/opengl/PGraphicsOpenGL.java +13753 -0
  98. data/lib/java/processing/opengl/PJOGL.java +2008 -0
  99. data/lib/java/processing/opengl/PShader.java +1484 -0
  100. data/lib/java/processing/opengl/PShapeOpenGL.java +5269 -0
  101. data/lib/java/processing/opengl/PSurfaceJOGL.java +1385 -0
  102. data/lib/java/processing/opengl/Texture.java +1696 -0
  103. data/lib/java/processing/opengl/VertexBuffer.java +88 -0
  104. data/lib/java/processing/opengl/cursors/arrow.png +0 -0
  105. data/lib/java/processing/opengl/cursors/cross.png +0 -0
  106. data/lib/java/processing/opengl/cursors/hand.png +0 -0
  107. data/lib/java/processing/opengl/cursors/license.txt +27 -0
  108. data/lib/java/processing/opengl/cursors/move.png +0 -0
  109. data/lib/java/processing/opengl/cursors/text.png +0 -0
  110. data/lib/java/processing/opengl/cursors/wait.png +0 -0
  111. data/lib/java/processing/opengl/shaders/ColorFrag.glsl +32 -0
  112. data/lib/java/processing/opengl/shaders/ColorVert.glsl +34 -0
  113. data/lib/java/processing/opengl/shaders/LightFrag.glsl +33 -0
  114. data/lib/java/processing/opengl/shaders/LightVert.glsl +151 -0
  115. data/lib/java/processing/opengl/shaders/LineFrag.glsl +32 -0
  116. data/lib/java/processing/opengl/shaders/LineVert.glsl +100 -0
  117. data/lib/java/processing/opengl/shaders/MaskFrag.glsl +40 -0
  118. data/lib/java/processing/opengl/shaders/PointFrag.glsl +32 -0
  119. data/lib/java/processing/opengl/shaders/PointVert.glsl +56 -0
  120. data/lib/java/processing/opengl/shaders/TexFrag.glsl +37 -0
  121. data/lib/java/processing/opengl/shaders/TexLightFrag.glsl +37 -0
  122. data/lib/java/processing/opengl/shaders/TexLightVert.glsl +157 -0
  123. data/lib/java/processing/opengl/shaders/TexVert.glsl +38 -0
  124. data/lib/java/processing/pdf/PGraphicsPDF.java +581 -0
  125. data/lib/java/processing/svg/PGraphicsSVG.java +378 -0
  126. data/lib/propane/app.rb +8 -13
  127. data/lib/propane/version.rb +1 -1
  128. data/mvnw +3 -3
  129. data/mvnw.cmd +2 -2
  130. data/pom.rb +7 -2
  131. data/pom.xml +14 -2
  132. data/propane.gemspec +2 -2
  133. data/src/main/java/monkstone/FastNoiseModuleJava.java +127 -0
  134. data/src/main/java/monkstone/MathToolModule.java +30 -30
  135. data/src/main/java/monkstone/PropaneLibrary.java +2 -0
  136. data/src/main/java/monkstone/SmoothNoiseModuleJava.java +127 -0
  137. data/src/main/java/monkstone/fastmath/DegLutTables.java +15 -15
  138. data/src/main/java/monkstone/filechooser/Chooser.java +1 -1
  139. data/src/main/java/monkstone/noise/OpenSimplex2F.java +752 -820
  140. data/src/main/java/monkstone/noise/OpenSimplex2S.java +1138 -1106
  141. data/src/main/java/monkstone/slider/WheelHandler.java +1 -1
  142. data/src/main/java/monkstone/vecmath/JRender.java +6 -6
  143. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +20 -19
  144. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +12 -12
  145. data/src/main/java/processing/awt/PGraphicsJava2D.java +11 -3
  146. data/src/main/java/processing/core/PApplet.java +89 -89
  147. data/src/main/java/processing/core/PConstants.java +155 -163
  148. data/src/main/java/processing/opengl/PJOGL.java +6 -5
  149. data/vendors/Rakefile +1 -1
  150. metadata +136 -19
@@ -0,0 +1,40 @@
1
+ /*
2
+ Part of the Processing project - http://processing.org
3
+
4
+ Copyright (c) 2012-15 The Processing Foundation
5
+ Copyright (c) 2004-12 Ben Fry and Casey Reas
6
+ Copyright (c) 2001-04 Massachusetts Institute of Technology
7
+
8
+ This library is free software; you can redistribute it and/or
9
+ modify it under the terms of the GNU Lesser General Public
10
+ License as published by the Free Software Foundation, version 2.1.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General
18
+ Public License along with this library; if not, write to the
19
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+ Boston, MA 02111-1307 USA
21
+ */
22
+
23
+ #ifdef GL_ES
24
+ precision mediump float;
25
+ precision mediump int;
26
+ #endif
27
+
28
+ #define PROCESSING_TEXTURE_SHADER
29
+
30
+ uniform sampler2D texture;
31
+ uniform sampler2D mask;
32
+
33
+ varying vec4 vertTexCoord;
34
+
35
+ void main() {
36
+ vec3 texColor = texture2D(texture, vertTexCoord.st).rgb;
37
+ vec3 maskColor = texture2D(mask, vertTexCoord.st).rgb;
38
+ float luminance = dot(maskColor, vec3(0.2126, 0.7152, 0.0722));
39
+ gl_FragColor = vec4(texColor, luminance);
40
+ }
@@ -0,0 +1,32 @@
1
+ /*
2
+ Part of the Processing project - http://processing.org
3
+
4
+ Copyright (c) 2012-15 The Processing Foundation
5
+ Copyright (c) 2004-12 Ben Fry and Casey Reas
6
+ Copyright (c) 2001-04 Massachusetts Institute of Technology
7
+
8
+ This library is free software; you can redistribute it and/or
9
+ modify it under the terms of the GNU Lesser General Public
10
+ License as published by the Free Software Foundation, version 2.1.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General
18
+ Public License along with this library; if not, write to the
19
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+ Boston, MA 02111-1307 USA
21
+ */
22
+
23
+ #ifdef GL_ES
24
+ precision mediump float;
25
+ precision mediump int;
26
+ #endif
27
+
28
+ varying vec4 vertColor;
29
+
30
+ void main() {
31
+ gl_FragColor = vertColor;
32
+ }
@@ -0,0 +1,56 @@
1
+ /*
2
+ Part of the Processing project - http://processing.org
3
+
4
+ Copyright (c) 2012-15 The Processing Foundation
5
+ Copyright (c) 2004-12 Ben Fry and Casey Reas
6
+ Copyright (c) 2001-04 Massachusetts Institute of Technology
7
+
8
+ This library is free software; you can redistribute it and/or
9
+ modify it under the terms of the GNU Lesser General Public
10
+ License as published by the Free Software Foundation, version 2.1.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General
18
+ Public License along with this library; if not, write to the
19
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+ Boston, MA 02111-1307 USA
21
+ */
22
+
23
+ uniform mat4 projectionMatrix;
24
+ uniform mat4 modelviewMatrix;
25
+
26
+ uniform vec4 viewport;
27
+ uniform int perspective;
28
+
29
+ attribute vec4 position;
30
+ attribute vec4 color;
31
+ attribute vec2 offset;
32
+
33
+ varying vec4 vertColor;
34
+
35
+ void main() {
36
+ vec4 pos = modelviewMatrix * position;
37
+ vec4 clip = projectionMatrix * pos;
38
+
39
+ // Perspective ---
40
+ // convert from world to clip by multiplying with projection scaling factor
41
+ // invert Y, projections in Processing invert Y
42
+ vec2 perspScale = (projectionMatrix * vec4(1, -1, 0, 0)).xy;
43
+
44
+ // formula to convert from clip space (range -1..1) to screen space (range 0..[width or height])
45
+ // screen_p = (p.xy/p.w + <1,1>) * 0.5 * viewport.zw
46
+
47
+ // No Perspective ---
48
+ // multiply by W (to cancel out division by W later in the pipeline) and
49
+ // convert from screen to clip (derived from clip to screen above)
50
+ vec2 noPerspScale = clip.w / (0.5 * viewport.zw);
51
+
52
+ gl_Position.xy = clip.xy + offset.xy * mix(noPerspScale, perspScale, float(perspective > 0));
53
+ gl_Position.zw = clip.zw;
54
+
55
+ vertColor = color;
56
+ }
@@ -0,0 +1,37 @@
1
+ /*
2
+ Part of the Processing project - http://processing.org
3
+
4
+ Copyright (c) 2012-15 The Processing Foundation
5
+ Copyright (c) 2004-12 Ben Fry and Casey Reas
6
+ Copyright (c) 2001-04 Massachusetts Institute of Technology
7
+
8
+ This library is free software; you can redistribute it and/or
9
+ modify it under the terms of the GNU Lesser General Public
10
+ License as published by the Free Software Foundation, version 2.1.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General
18
+ Public License along with this library; if not, write to the
19
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+ Boston, MA 02111-1307 USA
21
+ */
22
+
23
+ #ifdef GL_ES
24
+ precision mediump float;
25
+ precision mediump int;
26
+ #endif
27
+
28
+ uniform sampler2D texture;
29
+
30
+ uniform vec2 texOffset;
31
+
32
+ varying vec4 vertColor;
33
+ varying vec4 vertTexCoord;
34
+
35
+ void main() {
36
+ gl_FragColor = texture2D(texture, vertTexCoord.st) * vertColor;
37
+ }
@@ -0,0 +1,37 @@
1
+ /*
2
+ Part of the Processing project - http://processing.org
3
+
4
+ Copyright (c) 2012-15 The Processing Foundation
5
+ Copyright (c) 2004-12 Ben Fry and Casey Reas
6
+ Copyright (c) 2001-04 Massachusetts Institute of Technology
7
+
8
+ This library is free software; you can redistribute it and/or
9
+ modify it under the terms of the GNU Lesser General Public
10
+ License as published by the Free Software Foundation, version 2.1.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General
18
+ Public License along with this library; if not, write to the
19
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+ Boston, MA 02111-1307 USA
21
+ */
22
+ #ifdef GL_ES
23
+ precision mediump float;
24
+ precision mediump int;
25
+ #endif
26
+
27
+ uniform sampler2D texture;
28
+
29
+ uniform vec2 texOffset;
30
+
31
+ varying vec4 vertColor;
32
+ varying vec4 backVertColor;
33
+ varying vec4 vertTexCoord;
34
+
35
+ void main() {
36
+ gl_FragColor = texture2D(texture, vertTexCoord.st) * (gl_FrontFacing ? vertColor : backVertColor);
37
+ }
@@ -0,0 +1,157 @@
1
+ /*
2
+ Part of the Processing project - http://processing.org
3
+
4
+ Copyright (c) 2012-15 The Processing Foundation
5
+ Copyright (c) 2004-12 Ben Fry and Casey Reas
6
+ Copyright (c) 2001-04 Massachusetts Institute of Technology
7
+
8
+ This library is free software; you can redistribute it and/or
9
+ modify it under the terms of the GNU Lesser General Public
10
+ License as published by the Free Software Foundation, version 2.1.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General
18
+ Public License along with this library; if not, write to the
19
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+ Boston, MA 02111-1307 USA
21
+ */
22
+
23
+ uniform mat4 modelviewMatrix;
24
+ uniform mat4 transformMatrix;
25
+ uniform mat3 normalMatrix;
26
+ uniform mat4 texMatrix;
27
+
28
+ uniform int lightCount;
29
+ uniform vec4 lightPosition[8];
30
+ uniform vec3 lightNormal[8];
31
+ uniform vec3 lightAmbient[8];
32
+ uniform vec3 lightDiffuse[8];
33
+ uniform vec3 lightSpecular[8];
34
+ uniform vec3 lightFalloff[8];
35
+ uniform vec2 lightSpot[8];
36
+
37
+ attribute vec4 position;
38
+ attribute vec4 color;
39
+ attribute vec3 normal;
40
+ attribute vec2 texCoord;
41
+
42
+ attribute vec4 ambient;
43
+ attribute vec4 specular;
44
+ attribute vec4 emissive;
45
+ attribute float shininess;
46
+
47
+ varying vec4 vertColor;
48
+ varying vec4 backVertColor;
49
+ varying vec4 vertTexCoord;
50
+
51
+ const float zero_float = 0.0;
52
+ const float one_float = 1.0;
53
+ const vec3 zero_vec3 = vec3(0);
54
+
55
+ float falloffFactor(vec3 lightPos, vec3 vertPos, vec3 coeff) {
56
+ vec3 lpv = lightPos - vertPos;
57
+ vec3 dist = vec3(one_float);
58
+ dist.z = dot(lpv, lpv);
59
+ dist.y = sqrt(dist.z);
60
+ return one_float / dot(dist, coeff);
61
+ }
62
+
63
+ float spotFactor(vec3 lightPos, vec3 vertPos, vec3 lightNorm, float minCos, float spotExp) {
64
+ vec3 lpv = normalize(lightPos - vertPos);
65
+ vec3 nln = -one_float * lightNorm;
66
+ float spotCos = dot(nln, lpv);
67
+ return spotCos <= minCos ? zero_float : pow(spotCos, spotExp);
68
+ }
69
+
70
+ float lambertFactor(vec3 lightDir, vec3 vecNormal) {
71
+ return max(zero_float, dot(lightDir, vecNormal));
72
+ }
73
+
74
+ float blinnPhongFactor(vec3 lightDir, vec3 vertPos, vec3 vecNormal, float shine) {
75
+ vec3 np = normalize(vertPos);
76
+ vec3 ldp = normalize(lightDir - np);
77
+ return pow(max(zero_float, dot(ldp, vecNormal)), shine);
78
+ }
79
+
80
+ void main() {
81
+ // Vertex in clip coordinates
82
+ gl_Position = transformMatrix * position;
83
+
84
+ // Vertex in eye coordinates
85
+ vec3 ecVertex = vec3(modelviewMatrix * position);
86
+
87
+ // Normal vector in eye coordinates
88
+ vec3 ecNormal = normalize(normalMatrix * normal);
89
+ vec3 ecNormalInv = ecNormal * -one_float;
90
+
91
+ // Light calculations
92
+ vec3 totalAmbient = vec3(0, 0, 0);
93
+
94
+ vec3 totalFrontDiffuse = vec3(0, 0, 0);
95
+ vec3 totalFrontSpecular = vec3(0, 0, 0);
96
+
97
+ vec3 totalBackDiffuse = vec3(0, 0, 0);
98
+ vec3 totalBackSpecular = vec3(0, 0, 0);
99
+
100
+ for (int i = 0; i < 8; i++) {
101
+ if (lightCount == i) break;
102
+
103
+ vec3 lightPos = lightPosition[i].xyz;
104
+ bool isDir = lightPosition[i].w < one_float;
105
+ float spotCos = lightSpot[i].x;
106
+ float spotExp = lightSpot[i].y;
107
+
108
+ vec3 lightDir;
109
+ float falloff;
110
+ float spotf;
111
+
112
+ if (isDir) {
113
+ falloff = one_float;
114
+ lightDir = -one_float * lightNormal[i];
115
+ } else {
116
+ falloff = falloffFactor(lightPos, ecVertex, lightFalloff[i]);
117
+ lightDir = normalize(lightPos - ecVertex);
118
+ }
119
+
120
+ spotf = spotExp > zero_float ? spotFactor(lightPos, ecVertex, lightNormal[i],
121
+ spotCos, spotExp)
122
+ : one_float;
123
+
124
+ if (any(greaterThan(lightAmbient[i], zero_vec3))) {
125
+ totalAmbient += lightAmbient[i] * falloff;
126
+ }
127
+
128
+ if (any(greaterThan(lightDiffuse[i], zero_vec3))) {
129
+ totalFrontDiffuse += lightDiffuse[i] * falloff * spotf *
130
+ lambertFactor(lightDir, ecNormal);
131
+ totalBackDiffuse += lightDiffuse[i] * falloff * spotf *
132
+ lambertFactor(lightDir, ecNormalInv);
133
+ }
134
+
135
+ if (any(greaterThan(lightSpecular[i], zero_vec3))) {
136
+ totalFrontSpecular += lightSpecular[i] * falloff * spotf *
137
+ blinnPhongFactor(lightDir, ecVertex, ecNormal, shininess);
138
+ totalBackSpecular += lightSpecular[i] * falloff * spotf *
139
+ blinnPhongFactor(lightDir, ecVertex, ecNormalInv, shininess);
140
+ }
141
+ }
142
+
143
+ // Calculating final color as result of all lights (plus emissive term).
144
+ // Transparency is determined exclusively by the diffuse component.
145
+ vertColor = vec4(totalAmbient, 0) * ambient +
146
+ vec4(totalFrontDiffuse, 1) * color +
147
+ vec4(totalFrontSpecular, 0) * specular +
148
+ vec4(emissive.rgb, 0);
149
+
150
+ backVertColor = vec4(totalAmbient, 0) * ambient +
151
+ vec4(totalBackDiffuse, 1) * color +
152
+ vec4(totalBackSpecular, 0) * specular +
153
+ vec4(emissive.rgb, 0);
154
+
155
+ // Calculating texture coordinates, with r and q set both to one
156
+ vertTexCoord = texMatrix * vec4(texCoord, 1.0, 1.0);
157
+ }
@@ -0,0 +1,38 @@
1
+ /*
2
+ Part of the Processing project - http://processing.org
3
+
4
+ Copyright (c) 2012-15 The Processing Foundation
5
+ Copyright (c) 2004-12 Ben Fry and Casey Reas
6
+ Copyright (c) 2001-04 Massachusetts Institute of Technology
7
+
8
+ This library is free software; you can redistribute it and/or
9
+ modify it under the terms of the GNU Lesser General Public
10
+ License as published by the Free Software Foundation, version 2.1.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General
18
+ Public License along with this library; if not, write to the
19
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+ Boston, MA 02111-1307 USA
21
+ */
22
+
23
+ uniform mat4 transformMatrix;
24
+ uniform mat4 texMatrix;
25
+
26
+ attribute vec4 position;
27
+ attribute vec4 color;
28
+ attribute vec2 texCoord;
29
+
30
+ varying vec4 vertColor;
31
+ varying vec4 vertTexCoord;
32
+
33
+ void main() {
34
+ gl_Position = transformMatrix * position;
35
+
36
+ vertColor = color;
37
+ vertTexCoord = texMatrix * vec4(texCoord, 1.0, 1.0);
38
+ }
@@ -0,0 +1,581 @@
1
+ /*
2
+ Part of the Processing project - http://processing.org
3
+
4
+ Copyright (c) 2005-12 Ben Fry and Casey Reas
5
+ Copyright (c) 2012-18 The Processing Foundation
6
+
7
+ This library is free software; you can redistribute it and/or
8
+ modify it under the terms of the GNU Lesser General Public
9
+ License version 2.1 as published by the Free Software Foundation.
10
+
11
+ This library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General
17
+ Public License along with this library; if not, write to the
18
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19
+ Boston, MA 02111-1307 USA
20
+ */
21
+ package processing.pdf;
22
+
23
+ import com.itextpdf.awt.DefaultFontMapper;
24
+ import com.itextpdf.awt.PdfGraphics2D;
25
+ import com.itextpdf.text.Document;
26
+ import com.itextpdf.text.DocumentException;
27
+ import com.itextpdf.text.Rectangle;
28
+ import com.itextpdf.text.pdf.ByteBuffer;
29
+ import com.itextpdf.text.pdf.PdfContentByte;
30
+ import com.itextpdf.text.pdf.PdfWriter;
31
+ import java.awt.Font;
32
+ import java.awt.Graphics2D;
33
+ import java.awt.Image;
34
+ import java.io.BufferedOutputStream;
35
+ import java.io.File;
36
+ import java.io.FileNotFoundException;
37
+ import java.io.FileOutputStream;
38
+ import java.io.OutputStream;
39
+ import java.util.Arrays;
40
+ import java.util.HashMap;
41
+ import java.util.logging.Level;
42
+ import java.util.logging.Logger;
43
+ import processing.awt.PGraphicsJava2D;
44
+ import processing.core.PApplet;
45
+ import processing.core.PConstants;
46
+ import processing.core.PFont;
47
+ import processing.core.PImage;
48
+ import processing.core.PStyle;
49
+ import processing.core.PSurface;
50
+ import processing.core.PSurfaceNone;
51
+
52
+ /**
53
+ * Thin wrapper for the iText PDF library that handles writing PDF files. The
54
+ * majority of the work in this library is done by
55
+ * <a href="https://github.com/itext/itextpdf">itextpdf</a>. This is currently using
56
+ * itextpdf-5.5.13.2.
57
+ */
58
+ public class PGraphicsPDF extends PGraphicsJava2D {
59
+
60
+ /**
61
+ * File being written, if it's a file.
62
+ */
63
+ protected File file;
64
+ /**
65
+ * OutputStream being written to, if using an OutputStream.
66
+ */
67
+ protected OutputStream output;
68
+
69
+ protected Document document;
70
+ protected PdfWriter writer;
71
+ protected PdfContentByte content;
72
+ protected PdfGraphics2D graphicContent;
73
+ /**
74
+ * Shared across instances because it's incredibly time-consuming to create.
75
+ */
76
+ static protected DefaultFontMapper mapper;
77
+ static protected String[] fontList;
78
+
79
+ @Override
80
+ public void setPath(String path) {
81
+ this.path = path;
82
+ if (path != null) {
83
+ file = new File(path);
84
+ if (!file.isAbsolute()) {
85
+ file = null;
86
+ }
87
+ }
88
+ if (file == null) {
89
+ throw new RuntimeException("PGraphicsPDF requires an absolute path "
90
+ + "for the location of the output file.");
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Set the library to write to an output stream instead of a file.
96
+ * @param output
97
+ */
98
+ public void setOutput(OutputStream output) {
99
+ this.output = output;
100
+ }
101
+
102
+ @Override
103
+ public PSurface createSurface() {
104
+ return surface = new PSurfaceNone(this);
105
+ }
106
+
107
+ @Override
108
+ protected void defaultSettings() { // ignore
109
+ super.defaultSettings();
110
+ textMode = SHAPE;
111
+ }
112
+
113
+ @Override
114
+ public void beginDraw() {
115
+ if (document == null) {
116
+ ByteBuffer.HIGH_PRECISION = true;
117
+ document = new Document(new Rectangle(width, height));
118
+ boolean missingPath = false;
119
+ try {
120
+ if (file != null) {
121
+ try {
122
+ output = new BufferedOutputStream(new FileOutputStream(file), 16384);
123
+ } catch (FileNotFoundException ex) {
124
+ Logger.getLogger(PGraphicsPDF.class.getName()).log(Level.SEVERE, null, ex);
125
+ }
126
+ } else if (output == null) {
127
+ missingPath = true;
128
+ throw new RuntimeException("PGraphicsPDF requires a path "
129
+ + "for the location of the output file.");
130
+ }
131
+ try {
132
+ writer = PdfWriter.getInstance(document, output);
133
+ } catch (DocumentException ex) {
134
+ Logger.getLogger(PGraphicsPDF.class.getName()).log(Level.SEVERE, null, ex);
135
+ }
136
+ document.open();
137
+ content = writer.getDirectContent();
138
+ // template = content.createTemplate(width, height);
139
+
140
+ } catch (RuntimeException re) {
141
+ if (missingPath) {
142
+ throw re; // don't re-package our own error
143
+ } else {
144
+ throw new RuntimeException("Problem saving the PDF file.", re);
145
+ }
146
+ }
147
+ g2 = new PdfGraphics2D(content, width, height);
148
+ }
149
+
150
+ // super in Java2D now creates an image buffer, don't do that
151
+ //super.beginDraw();
152
+ checkSettings();
153
+ resetMatrix(); // reset model matrix
154
+ vertexCount = 0;
155
+ pushMatrix();
156
+ }
157
+
158
+ static protected DefaultFontMapper getMapper() {
159
+ if (mapper == null) {
160
+ mapper = new DefaultFontMapper();
161
+ switch (PApplet.platform) {
162
+ case PConstants.MACOS:
163
+ try {
164
+ String homeLibraryFonts
165
+ = System.getProperty("user.home") + "/Library/Fonts";
166
+ mapper.insertDirectory(homeLibraryFonts);
167
+ } catch (Exception e) {
168
+ // might be a security issue with getProperty() and user.home
169
+ // if this sketch is running from the web
170
+ } // add the system font paths
171
+ mapper.insertDirectory("/System/Library/Fonts");
172
+ mapper.insertDirectory("/Library/Fonts");
173
+ break;
174
+
175
+ case PConstants.WINDOWS:
176
+ // how to get the windows fonts directory?
177
+ // could be c:\winnt\fonts or c:\windows\fonts or not even c:
178
+ // maybe do a Runtime.exec() on echo %WINDIR% ?
179
+ // Runtime.exec solution might be a mess on systems where the
180
+ // the backslash/colon characters not really used (i.e. JP)
181
+
182
+ // find the windows fonts folder
183
+ File roots[] = File.listRoots();
184
+ for (File root : roots) {
185
+ if (root.toString().startsWith("A:")) {
186
+ // Seems to be a problem with some machines that the A:
187
+ // drive is returned as an actual root, even if not available.
188
+ // This won't fix the issue if the same thing happens with
189
+ // other removable drive devices, but should fix the
190
+ // initial/problem as cited by the bug report:
191
+ // http://dev.processing.org/bugs/show_bug.cgi?id=478
192
+ // If not, will need to use the other fileExists() code below.
193
+ continue;
194
+ }
195
+ File folder = new File(root, "WINDOWS/Fonts");
196
+ if (folder.exists()) {
197
+ mapper.insertDirectory(folder.getAbsolutePath());
198
+ break;
199
+ }
200
+ folder = new File(root, "WINNT/Fonts");
201
+ if (folder.exists()) {
202
+ mapper.insertDirectory(folder.getAbsolutePath());
203
+ break;
204
+ }
205
+ }
206
+ break;
207
+
208
+ case PConstants.LINUX:
209
+ checkDir("/usr/share/fonts/", mapper);
210
+ checkDir("/usr/local/share/fonts/", mapper);
211
+ checkDir(System.getProperty("user.home") + "/.fonts", mapper);
212
+ break;
213
+ default:
214
+ break;
215
+ }
216
+ }
217
+ return mapper;
218
+ }
219
+
220
+ static protected void checkDir(String path, DefaultFontMapper mapper) {
221
+ File folder = new File(path);
222
+ if (folder.exists()) {
223
+ mapper.insertDirectory(path);
224
+ traverseDir(folder, mapper);
225
+ }
226
+ }
227
+
228
+ /**
229
+ * Recursive walk to get all subdirectories for font fun.Patch submitted by
230
+ * Matthias
231
+ * Breuer.(<a href="http://dev.processing.org/bugs/show_bug.cgi?id=1566">Bug
232
+ * 1566</a>)
233
+ *
234
+ * @param folder
235
+ * @param mapper
236
+ */
237
+ static protected void traverseDir(File folder, DefaultFontMapper mapper) {
238
+ File[] files = folder.listFiles();
239
+ for (File file1 : files) {
240
+ if (file1.isDirectory()) {
241
+ mapper.insertDirectory(file1.getPath());
242
+ traverseDir(new File(file1.getPath()), mapper);
243
+ }
244
+ }
245
+ }
246
+
247
+ // endDraw() needs to be overridden so that the endDraw() from
248
+ // PGraphicsJava2D is not inherited (it calls loadPixels).
249
+ // http://dev.processing.org/bugs/show_bug.cgi?id=1169
250
+ @Override
251
+ public void endDraw() {
252
+ // Also need to pop the matrix since the matrix doesn't reset on each run
253
+ // http://dev.processing.org/bugs/show_bug.cgi?id=1227
254
+ popMatrix();
255
+ }
256
+
257
+ /**
258
+ * Call to explicitly go to the next page from within a single draw().
259
+ */
260
+ public void nextPage() {
261
+ PStyle savedStyle = getStyle();
262
+ endDraw();
263
+ g2.dispose();
264
+
265
+ try {
266
+ // writer.setPageEmpty(false); // maybe useful later
267
+ document.newPage(); // is this bad if no addl pages are made?
268
+ } catch (Exception e) {
269
+ }
270
+ g2 = createGraphics();
271
+ beginDraw();
272
+ style(savedStyle);
273
+ }
274
+
275
+ protected Graphics2D createGraphics() {
276
+ if (textMode == SHAPE) {
277
+ return new PdfGraphics2D(content, width, height);
278
+ } else if (textMode == MODEL) {
279
+ return new PdfGraphics2D(content, width, height, getMapper());
280
+ }
281
+ // Should not be reachable...
282
+ throw new RuntimeException("Invalid textMode() selected for PDF.");
283
+ }
284
+
285
+ @Override
286
+ public void dispose() {
287
+ if (document != null) {
288
+ g2.dispose();
289
+ document.close(); // can't be done in finalize, not always called
290
+ document = null;
291
+ }
292
+ //new Exception().printStackTrace(System.out);
293
+ }
294
+
295
+ /**
296
+ * Don't open a window for this renderer, it won't be used.
297
+ * @return
298
+ */
299
+ @Override
300
+ public boolean displayable() {
301
+ return false;
302
+ }
303
+
304
+ @Override
305
+ protected void imageImpl(PImage image,
306
+ float x1, float y1, float x2, float y2,
307
+ int u1, int v1, int u2, int v2) {
308
+ pushMatrix();
309
+ translate(x1, y1);
310
+ int imageWidth = image.width;
311
+ int imageHeight = image.height;
312
+ scale((x2 - x1) / imageWidth,
313
+ (y2 - y1) / imageHeight);
314
+ if (u2 - u1 == imageWidth && v2 - v1 == imageHeight) {
315
+ g2.drawImage((Image) image.getNative(), 0, 0, null);
316
+ } else {
317
+ PImage tmp = image.get(u1, v1, u2 - u1, v2 - v1);
318
+ g2.drawImage((Image) tmp.getNative(), 0, 0, null);
319
+ }
320
+ popMatrix();
321
+ }
322
+
323
+ //////////////////////////////////////////////////////////////
324
+ @Override
325
+ public void textFont(PFont which) {
326
+ super.textFont(which);
327
+ checkFont();
328
+ }
329
+
330
+ /**
331
+ * Change the textMode() to either SHAPE or MODEL. This resets all renderer
332
+ * settings, and therefore must be called
333
+ * <EM>before</EM> any other commands that set the fill() or the textFont()
334
+ * or anything. Unlike other renderers, use textMode() directly after the
335
+ * size() command.
336
+ */
337
+ @Override
338
+ public void textMode(int mode) {
339
+ if (textMode != mode) {
340
+ switch (mode) {
341
+ case SHAPE:
342
+ textMode = SHAPE;
343
+ g2.dispose();
344
+ g2 = createGraphics();
345
+ break;
346
+ case MODEL:
347
+ textMode = MODEL;
348
+ g2.dispose();
349
+ g2 = createGraphics();
350
+ break;
351
+ case SCREEN:
352
+ throw new RuntimeException("textMode(SCREEN) not supported with PDF");
353
+ default:
354
+ throw new RuntimeException("That textMode() does not exist");
355
+ }
356
+ }
357
+ }
358
+
359
+ @Override
360
+ protected void textLineImpl(char buffer[], int start, int stop,
361
+ float x, float y) {
362
+ checkFont();
363
+ super.textLineImpl(buffer, start, stop, x, y);
364
+ }
365
+
366
+ //////////////////////////////////////////////////////////////
367
+ @Override
368
+ public void loadPixels() {
369
+ nope("loadPixels");
370
+ }
371
+
372
+ @Override
373
+ public void updatePixels() {
374
+ nope("updatePixels");
375
+ }
376
+
377
+ @Override
378
+ public void updatePixels(int x, int y, int c, int d) {
379
+ nope("updatePixels");
380
+ }
381
+
382
+ //
383
+ @Override
384
+ public int get(int x, int y) {
385
+ nope("get");
386
+ return 0; // not reached
387
+ }
388
+
389
+ @Override
390
+ public PImage get(int x, int y, int c, int d) {
391
+ nope("get");
392
+ return null; // not reached
393
+ }
394
+
395
+ @Override
396
+ public PImage get() {
397
+ nope("get");
398
+ return null; // not reached
399
+ }
400
+
401
+ @Override
402
+ public void set(int x, int y, int argb) {
403
+ nope("set");
404
+ }
405
+
406
+ @Override
407
+ public void set(int x, int y, PImage image) {
408
+ nope("set");
409
+ }
410
+
411
+ //
412
+ /**
413
+ *
414
+ * @param alpha
415
+ */
416
+ @Override
417
+ public void mask(int alpha[]) {
418
+ nope("mask");
419
+ }
420
+
421
+ @Override
422
+ public void mask(PImage alpha) {
423
+ nope("mask");
424
+ }
425
+
426
+ /**
427
+ *
428
+ * @param kind
429
+ */
430
+ @Override
431
+ public void filter(int kind) {
432
+ nope("filter");
433
+ }
434
+
435
+ @Override
436
+ public void filter(int kind, float param) {
437
+ nope("filter");
438
+ }
439
+
440
+ //
441
+ @Override
442
+ protected void blendModeImpl() {
443
+ if (blendMode != REPLACE && blendMode != BLEND) {
444
+ showMissingWarning("blendMode");
445
+ }
446
+ }
447
+
448
+ //
449
+ @Override
450
+ public void copy(int sx1, int sy1, int sx2, int sy2,
451
+ int dx1, int dy1, int dx2, int dy2) {
452
+ nope("copy");
453
+ }
454
+
455
+ /**
456
+ *
457
+ * @param src
458
+ * @param sx1
459
+ * @param sy1
460
+ * @param sx2
461
+ * @param sy2
462
+ * @param dx1
463
+ * @param dy1
464
+ * @param dx2
465
+ * @param dy2
466
+ */
467
+ @Override
468
+ public void copy(PImage src,
469
+ int sx1, int sy1, int sx2, int sy2,
470
+ int dx1, int dy1, int dx2, int dy2) {
471
+ nope("copy");
472
+ }
473
+
474
+ //
475
+ public void blend(int sx, int sy, int dx, int dy, int mode) {
476
+ nope("blend");
477
+ }
478
+
479
+ public void blend(PImage src,
480
+ int sx, int sy, int dx, int dy, int mode) {
481
+ nope("blend");
482
+ }
483
+
484
+ @Override
485
+ public void blend(int sx1, int sy1, int sx2, int sy2,
486
+ int dx1, int dy1, int dx2, int dy2, int mode) {
487
+ nope("blend");
488
+ }
489
+
490
+ @Override
491
+ public void blend(PImage src,
492
+ int sx1, int sy1, int sx2, int sy2,
493
+ int dx1, int dy1, int dx2, int dy2, int mode) {
494
+ nope("blend");
495
+ }
496
+
497
+ //
498
+ @Override
499
+ public boolean save(String filename) {
500
+ nope("save");
501
+ return false;
502
+ }
503
+
504
+ //////////////////////////////////////////////////////////////
505
+ /**
506
+ * On Linux or any other platform, you'll need to add the directories by
507
+ * hand. (If there are actual standards here that we can use as a starting
508
+ * point, please file a bug to make a note of it)
509
+ *
510
+ * @param directory
511
+ */
512
+ public void addFonts(String directory) {
513
+ mapper.insertDirectory(directory);
514
+ }
515
+
516
+ /**
517
+ * Check whether the specified font can be used with the PDF library.
518
+ *
519
+ */
520
+ protected void checkFont() {
521
+ Font awtFont = (Font) textFont.getNative();
522
+ if (awtFont == null) { // always need a native font or reference to it
523
+ throw new RuntimeException("Use createFont() instead of loadFont() "
524
+ + "when drawing text using the PDF library.");
525
+ } else if (textMode != SHAPE) {
526
+ if (textFont.isStream()) {
527
+ throw new RuntimeException("Use textMode(SHAPE) with PDF when loading "
528
+ + ".ttf and .otf files with createFont().");
529
+ } else if (mapper.getAliases().get(textFont.getName()) == null) {
530
+ //System.out.println("alias for " + name + " = " + mapper.getAliases().get(name));
531
+ // System.err.println("Use PGraphicsPDF.listFonts() to get a list of " +
532
+ // "fonts that can be used with PDF.");
533
+ // throw new RuntimeException("The font “" + textFont.getName() + "” " +
534
+ // "cannot be used with PDF Export.");
535
+ if (textFont.getName().equals("Lucida Sans")) {
536
+ throw new RuntimeException("Use textMode(SHAPE) with the default "
537
+ + "font when exporting to PDF.");
538
+ } else {
539
+ throw new RuntimeException("Use textMode(SHAPE) with "
540
+ + "“" + textFont.getName() + "” "
541
+ + "when exporting to PDF.");
542
+ }
543
+ }
544
+ }
545
+ }
546
+
547
+ /**
548
+ * List the fonts known to the PDF renderer.This is like PFont.list(),
549
+ * however not all those fonts are available by default.
550
+ *
551
+ * @return
552
+ */
553
+ static public String[] listFonts() {
554
+ if (fontList == null) {
555
+ HashMap<?, ?> map = getMapper().getAliases();
556
+ // Set entries = map.entrySet();
557
+ // fontList = new String[entries.size()];
558
+ fontList = new String[map.size()];
559
+ int count = 0;
560
+ for (Object key : map.keySet()) {
561
+ // for (Object entry : map.entrySet()) {
562
+ // fontList[count++] = (String) ((Map.Entry) entry).getKey();
563
+ fontList[count++] = (String) key;
564
+ }
565
+ // Iterator it = entries.iterator();
566
+ // int count = 0;
567
+ // while (it.hasNext()) {
568
+ // Map.Entry entry = (Map.Entry) it.next();
569
+ // //System.out.println(entry.getKey() + "-->" + entry.getValue());
570
+ // fontList[count++] = (String) entry.getKey();
571
+ // }
572
+ Arrays.sort(fontList);
573
+ }
574
+ return fontList;
575
+ }
576
+
577
+ //////////////////////////////////////////////////////////////
578
+ protected void nope(String function) {
579
+ throw new RuntimeException("No " + function + "() for " + getClass().getSimpleName());
580
+ }
581
+ }