Lines 279-284
Link Here
|
279 |
} |
279 |
} |
280 |
|
280 |
|
281 |
/** |
281 |
/** |
|
|
282 |
* Get the string buffer from the currentStream, containing all |
283 |
* the commands written into this Grpahics so far. |
284 |
* @return the StringBuffer containing the PDF markup |
285 |
*/ |
286 |
public StringBuffer getBuffer() { |
287 |
return currentStream.getBuffer(); |
288 |
} |
289 |
|
290 |
/** |
282 |
* Set the Grpahics context. |
291 |
* Set the Grpahics context. |
283 |
* @param c the graphics context to use |
292 |
* @param c the graphics context to use |
284 |
*/ |
293 |
*/ |
Lines 829-845
Link Here
|
829 |
LinearGradientPaint gp = (LinearGradientPaint)paint; |
838 |
LinearGradientPaint gp = (LinearGradientPaint)paint; |
830 |
Color[] cols = gp.getColors(); |
839 |
Color[] cols = gp.getColors(); |
831 |
float[] fractions = gp.getFractions(); |
840 |
float[] fractions = gp.getFractions(); |
832 |
Point2D p1 = gp.getStartPoint(); |
841 |
|
833 |
Point2D p2 = gp.getEndPoint(); |
|
|
834 |
//MultipleGradientPaint.CycleMethodEnum cycenum = gp.getCycleMethod(); |
842 |
//MultipleGradientPaint.CycleMethodEnum cycenum = gp.getCycleMethod(); |
835 |
//boolean cyclic = (cycenum == MultipleGradientPaint.REPEAT); |
843 |
//boolean cyclic = (cycenum == MultipleGradientPaint.REPEAT); |
836 |
AffineTransform transform = graphicsState.getTransform(); |
844 |
// This code currently doesn't support 'repeat' as PDF has |
|
|
845 |
// no way to support this (we need to rasterize). |
846 |
|
847 |
// Build proper transform from gradient space to page space |
848 |
// ('Patterns' don't get userspace transform). |
849 |
AffineTransform transform; |
850 |
transform = new AffineTransform(graphicsState.getTransform()); |
851 |
transform.concatenate(getTransform()); |
837 |
transform.concatenate(gp.getTransform()); |
852 |
transform.concatenate(gp.getTransform()); |
838 |
transform.concatenate(getTransform()); |
|
|
839 |
|
853 |
|
840 |
p1 = transform.transform(p1, null); |
854 |
List theMatrix = new java.util.ArrayList(); |
841 |
p2 = transform.transform(p2, null); |
855 |
double [] mat = new double[6]; |
|
|
856 |
transform.getMatrix(mat); |
857 |
for (int idx=0; idx<mat.length; idx++) |
858 |
theMatrix.add(new Double(mat[idx])); |
842 |
|
859 |
|
|
|
860 |
Point2D p1 = gp.getStartPoint(); |
861 |
Point2D p2 = gp.getEndPoint(); |
843 |
List theCoords = new java.util.ArrayList(); |
862 |
List theCoords = new java.util.ArrayList(); |
844 |
theCoords.add(new Double(p1.getX())); |
863 |
theCoords.add(new Double(p1.getX())); |
845 |
theCoords.add(new Double(p1.getY())); |
864 |
theCoords.add(new Double(p1.getY())); |
Lines 874-919
Link Here
|
874 |
} |
893 |
} |
875 |
} |
894 |
} |
876 |
|
895 |
|
877 |
PDFColorSpace aColorSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB); |
896 |
PDFColorSpace aColorSpace; |
|
|
897 |
aColorSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB); |
878 |
PDFPattern myPat = pdfDoc.getFactory().makeGradient( |
898 |
PDFPattern myPat = pdfDoc.getFactory().makeGradient( |
879 |
resourceContext, false, aColorSpace, |
899 |
resourceContext, false, aColorSpace, |
880 |
someColors, theBounds, theCoords); |
900 |
someColors, theBounds, theCoords, theMatrix); |
881 |
currentStream.write(myPat.getColorSpaceOut(fill)); |
901 |
currentStream.write(myPat.getColorSpaceOut(fill)); |
882 |
|
902 |
|
883 |
} else if (paint instanceof RadialGradientPaint) { |
903 |
} else if (paint instanceof RadialGradientPaint) { |
884 |
RadialGradientPaint rgp = (RadialGradientPaint)paint; |
904 |
RadialGradientPaint rgp = (RadialGradientPaint)paint; |
885 |
|
905 |
|
|
|
906 |
AffineTransform transform; |
907 |
transform = new AffineTransform(graphicsState.getTransform()); |
908 |
transform.concatenate(getTransform()); |
909 |
transform.concatenate(rgp.getTransform()); |
910 |
|
911 |
List theMatrix = new java.util.ArrayList(); |
912 |
double [] mat = new double[6]; |
913 |
transform.getMatrix(mat); |
914 |
for (int idx=0; idx<mat.length; idx++) |
915 |
theMatrix.add(new Double(mat[idx])); |
916 |
|
886 |
double ar = rgp.getRadius(); |
917 |
double ar = rgp.getRadius(); |
887 |
Point2D ac = rgp.getCenterPoint(); |
918 |
Point2D ac = rgp.getCenterPoint(); |
888 |
Point2D af = rgp.getFocusPoint(); |
919 |
Point2D af = rgp.getFocusPoint(); |
889 |
AffineTransform transform = graphicsState.getTransform(); |
|
|
890 |
AffineTransform gradt = rgp.getTransform(); |
891 |
transform.concatenate(gradt); |
892 |
|
920 |
|
893 |
// find largest scaling for the radius |
921 |
List theCoords = new java.util.ArrayList(); |
894 |
double scale = gradt.getScaleX(); |
922 |
double dx = af.getX()-ac.getX(); |
895 |
if (gradt.getScaleY() > scale) { |
923 |
double dy = af.getY()-ac.getY(); |
896 |
scale = gradt.getScaleY(); |
924 |
double d = Math.sqrt(dx*dx+dy*dy); |
|
|
925 |
if (d > ar) { |
926 |
// the center point af must be within the circle with |
927 |
// radius ar centered at ac so limit it to that. |
928 |
double scale = (ar*.9999)/d; |
929 |
dx = dx*scale; |
930 |
dy = dy*scale; |
897 |
} |
931 |
} |
898 |
ar = ar * scale; |
|
|
899 |
ac = transform.transform(ac, null); |
900 |
af = transform.transform(af, null); |
901 |
|
932 |
|
902 |
List theCoords = new java.util.ArrayList(); |
933 |
theCoords.add(new Double(ac.getX()+dx)); // Fx |
903 |
// the center point af must be within the circle with |
934 |
theCoords.add(new Double(ac.getY()+dy)); // Fy |
904 |
// radius ar centered at ac |
|
|
905 |
theCoords.add(new Double(af.getX())); |
906 |
theCoords.add(new Double(af.getY())); |
907 |
theCoords.add(new Double(0)); |
935 |
theCoords.add(new Double(0)); |
908 |
theCoords.add(new Double(ac.getX())); // Fx |
936 |
theCoords.add(new Double(ac.getX())); |
909 |
theCoords.add(new Double(ac.getY())); // Fy |
937 |
theCoords.add(new Double(ac.getY())); |
910 |
theCoords.add(new Double(ar)); |
938 |
theCoords.add(new Double(ar)); |
911 |
|
939 |
|
912 |
Color[] cols = rgp.getColors(); |
940 |
Color[] cols = rgp.getColors(); |
913 |
List someColors = new java.util.ArrayList(); |
941 |
List someColors = new java.util.ArrayList(); |
914 |
for (int count = 0; count < cols.length; count++) { |
942 |
for (int count = 0; count < cols.length; count++) { |
915 |
Color cc = cols[count]; |
943 |
Color cc = cols[count]; |
916 |
someColors.add(new PDFColor(cc.getRed(), cc.getGreen(), cc.getBlue())); |
944 |
someColors.add(new PDFColor(cc.getRed(), cc.getGreen(), |
|
|
945 |
cc.getBlue())); |
917 |
} |
946 |
} |
918 |
|
947 |
|
919 |
float[] fractions = rgp.getFractions(); |
948 |
float[] fractions = rgp.getFractions(); |
Lines 922-932
Link Here
|
922 |
float offset = fractions[count]; |
951 |
float offset = fractions[count]; |
923 |
theBounds.add(new Double(offset)); |
952 |
theBounds.add(new Double(offset)); |
924 |
} |
953 |
} |
925 |
PDFColorSpace colSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB); |
954 |
PDFColorSpace colSpace; |
926 |
PDFPattern myPat = pdfDoc.getFactory().makeGradient( |
955 |
colSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB); |
927 |
resourceContext, true, colSpace, |
|
|
928 |
someColors, theBounds, theCoords); |
929 |
|
956 |
|
|
|
957 |
PDFPattern myPat = pdfDoc.getFactory().makeGradient |
958 |
(resourceContext, true, colSpace, |
959 |
someColors, theBounds, theCoords, theMatrix); |
960 |
|
930 |
currentStream.write(myPat.getColorSpaceOut(fill)); |
961 |
currentStream.write(myPat.getColorSpaceOut(fill)); |
931 |
|
962 |
|
932 |
} else if (paint instanceof PatternPaint) { |
963 |
} else if (paint instanceof PatternPaint) { |
Lines 937-943
Link Here
|
937 |
|
968 |
|
938 |
private void createPattern(PatternPaint pp, boolean fill) { |
969 |
private void createPattern(PatternPaint pp, boolean fill) { |
939 |
preparePainting(); |
970 |
preparePainting(); |
940 |
Rectangle2D rect = pp.getPatternRect(); |
|
|
941 |
|
971 |
|
942 |
FontInfo fontInfo = new FontInfo(); |
972 |
FontInfo fontInfo = new FontInfo(); |
943 |
FontSetup.setup(fontInfo, null); |
973 |
FontSetup.setup(fontInfo, null); |
Lines 947-988
Link Here
|
947 |
PDFGraphics2D pattGraphic = new PDFGraphics2D(textAsShapes, fontInfo, |
977 |
PDFGraphics2D pattGraphic = new PDFGraphics2D(textAsShapes, fontInfo, |
948 |
pdfDoc, context, pageRef, |
978 |
pdfDoc, context, pageRef, |
949 |
"", 0); |
979 |
"", 0); |
950 |
pattGraphic.gc = (GraphicContext)this.gc.clone(); |
980 |
pattGraphic.setGraphicContext(new GraphicContext()); |
951 |
pattGraphic.gc.validateTransformStack(); |
981 |
pattGraphic.gc.validateTransformStack(); |
|
|
982 |
pattGraphic.setRenderingHints(this.getRenderingHints()); |
952 |
pattGraphic.setOutputStream(outputStream); |
983 |
pattGraphic.setOutputStream(outputStream); |
953 |
|
984 |
|
954 |
GraphicsNode gn = pp.getGraphicsNode(); |
985 |
GraphicsNode gn = pp.getGraphicsNode(); |
955 |
gn.paint(pattGraphic); |
986 |
Rectangle2D gnBBox = gn.getBounds(); |
|
|
987 |
Rectangle2D rect = pp.getPatternRect(); |
956 |
|
988 |
|
957 |
StringWriter pattStream = new StringWriter(); |
989 |
if (pp.getOverflow()) { |
958 |
pattStream.write("q\n"); |
990 |
// For overflow we need to paint the content from |
|
|
991 |
// all the tiles who's overflow will intersect one |
992 |
// tile (left->right, top->bottom). Then we can |
993 |
// simply replicate that tile as normal. |
994 |
double gnMinX = gnBBox.getX(); |
995 |
double gnMaxX = gnBBox.getX() + gnBBox.getWidth(); |
996 |
double gnMinY = gnBBox.getY(); |
997 |
double gnMaxY = gnBBox.getY() + gnBBox.getHeight(); |
998 |
double patMaxX = rect.getX() + rect.getWidth(); |
999 |
double patMaxY = rect.getY() + rect.getHeight(); |
1000 |
double stepX = rect.getWidth(); |
1001 |
double stepY = rect.getHeight(); |
959 |
|
1002 |
|
960 |
// this makes the pattern the right way up, since |
1003 |
int startX = (int)((rect.getX() - gnMaxX)/stepX); |
961 |
// it is outside the original transform around the |
1004 |
int startY = (int)((rect.getY() - gnMaxY)/stepY); |
962 |
// whole svg document |
|
|
963 |
pattStream.write("1 0 0 -1 0 " + (rect.getHeight() + rect.getY()) + " cm\n"); |
964 |
|
1005 |
|
965 |
pattStream.write(pattGraphic.getString()); |
1006 |
int endX = (int)((patMaxX - gnMinX)/stepX); |
966 |
pattStream.write("Q"); |
1007 |
int endY = (int)((patMaxY - gnMinY)/stepY); |
967 |
|
1008 |
|
|
|
1009 |
pattGraphic.translate(startX*stepX, startY*stepY); |
1010 |
for (int yIdx=startY; yIdx<=endY; yIdx++) { |
1011 |
for (int xIdx=startX; xIdx<=endX; xIdx++) { |
1012 |
gn.paint(pattGraphic); |
1013 |
pattGraphic.translate(stepX,0); |
1014 |
} |
1015 |
pattGraphic.translate(-(endX-startX+1)*stepX, stepY); |
1016 |
} |
1017 |
|
1018 |
} else { |
1019 |
gn.paint(pattGraphic); |
1020 |
} |
1021 |
|
1022 |
|
968 |
List bbox = new java.util.ArrayList(); |
1023 |
List bbox = new java.util.ArrayList(); |
969 |
bbox.add(new Double(0)); |
1024 |
bbox.add(new Double(rect.getX())); |
970 |
bbox.add(new Double(0)); |
1025 |
bbox.add(new Double(rect.getHeight()+rect.getY())); |
971 |
bbox.add(new Double(rect.getWidth() + rect.getX())); |
1026 |
bbox.add(new Double(rect.getWidth() +rect.getX())); |
972 |
bbox.add(new Double(rect.getHeight() + rect.getY())); |
1027 |
bbox.add(new Double(rect.getY())); |
973 |
|
1028 |
|
974 |
List translate = new java.util.ArrayList(); |
1029 |
AffineTransform transform; |
975 |
AffineTransform pattt = pp.getPatternTransform(); |
1030 |
transform = new AffineTransform(graphicsState.getTransform()); |
976 |
pattt.translate(rect.getWidth() + rect.getX(), rect.getHeight() + rect.getY()); |
1031 |
transform.concatenate(getTransform()); |
977 |
double[] flatmatrix = new double[6]; |
1032 |
transform.concatenate(pp.getPatternTransform()); |
978 |
pattt.getMatrix(flatmatrix); |
|
|
979 |
translate.add(new Double(flatmatrix[0])); |
980 |
translate.add(new Double(flatmatrix[1])); |
981 |
translate.add(new Double(flatmatrix[2])); |
982 |
translate.add(new Double(flatmatrix[3])); |
983 |
translate.add(new Double(flatmatrix[4])); |
984 |
translate.add(new Double(flatmatrix[5])); |
985 |
|
1033 |
|
|
|
1034 |
List theMatrix = new java.util.ArrayList(); |
1035 |
double [] mat = new double[6]; |
1036 |
transform.getMatrix(mat); |
1037 |
for (int idx=0; idx<mat.length; idx++) |
1038 |
theMatrix.add(new Double(mat[idx])); |
1039 |
|
986 |
/** @todo see if pdfDoc and res can be linked here, |
1040 |
/** @todo see if pdfDoc and res can be linked here, |
987 |
(currently res <> PDFDocument's resources) so addFonts() |
1041 |
(currently res <> PDFDocument's resources) so addFonts() |
988 |
can be moved to PDFDocument class */ |
1042 |
can be moved to PDFDocument class */ |
Lines 991-997
Link Here
|
991 |
PDFPattern myPat = pdfDoc.getFactory().makePattern( |
1045 |
PDFPattern myPat = pdfDoc.getFactory().makePattern( |
992 |
resourceContext, 1, res, 1, 1, bbox, |
1046 |
resourceContext, 1, res, 1, 1, bbox, |
993 |
rect.getWidth(), rect.getHeight(), |
1047 |
rect.getWidth(), rect.getHeight(), |
994 |
translate, null, pattStream.getBuffer()); |
1048 |
theMatrix, null, |
|
|
1049 |
pattGraphic.getBuffer()); |
995 |
|
1050 |
|
996 |
currentStream.write(myPat.getColorSpaceOut(fill)); |
1051 |
currentStream.write(myPat.getColorSpaceOut(fill)); |
997 |
|
1052 |
|