- Timestamp:
- 07/08/11 15:57:05 (11 months ago)
- Location:
- print/trunk
- Files:
-
- 5 modified
-
docs/configuration.txt (modified) (2 diffs)
-
docs/protocol.txt (modified) (1 diff)
-
src/main/java/org/mapfish/print/PDFUtils.java (modified) (3 diffs)
-
src/main/java/org/mapfish/print/config/Config.java (modified) (1 diff)
-
src/main/java/org/mapfish/print/config/layout/LegendsBlock.java (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
print/trunk/docs/configuration.txt
r3750 r3831 515 515 516 516 - !legends 517 ? maxIconWidth: 8 517 ? maxIconWidth: 8 518 518 ? maxIconHeight: 8 519 ? defaultScale: 0 520 ? inline: true 519 521 ? classIndentation: 20 520 522 ? layerSpace: 5 … … 527 529 ? fontEncoding: Cp1252 528 530 531 **maxIconWidth**, **maxIconHeight**, **defaultScale** with value of 0 indicates that the value will be ignore. 532 533 if **defaultScale** is non null it means that the legend image will be scaled so it doesn't take the full space. 534 535 Set **inline** to false mean that only tne image will be display per line. 536 529 537 **layerSpace** and **classSpace** is to specify the line space to add before layers and classes. 530 538 531 For this to work, you need to set the **layerTree** config option on MF print widgets. 539 For this to work, you need to set the **layerTree** config option on MF print widgets, 540 more precisely the legends should be present in the print.pdf JSON request. 532 541 533 542 Table configuration -
print/trunk/docs/protocol.txt
r3677 r3831 92 92 } 93 93 ] 94 legends: [ 95 { 96 classes: [ 97 { 98 icons: [ 99 'full url to the image' 100 ] 101 name: 'an icon name' 102 } 103 ] 104 name: 'a class name' 105 } 106 ] 94 107 } 95 108 -
print/trunk/src/main/java/org/mapfish/print/PDFUtils.java
r3827 r3831 68 68 */ 69 69 public static Image getImage(RenderingContext context, URI uri, float w, float h) throws IOException, DocumentException { 70 return getImage(context, uri, w, h, 0f); 71 } 72 73 /** 74 * Gets an iText image with a cache that uses PdfTemplates to re-use the same 75 * bitmap content multiple times in order to reduce the file size. 76 */ 77 public static Image getImage(RenderingContext context, URI uri, float w, float h, float scale) throws IOException, DocumentException { 70 78 //Check the image is not already used in the PDF file. 71 79 // … … 89 97 if (w == 0.0f) { 90 98 if (h == 0.0f) { 91 w = template.getWidth(); 92 h = template.getHeight(); 99 scale = scale == 0f ? 1f : scale; 100 w = template.getWidth() * scale; 101 h = template.getHeight() * scale; 93 102 } else { 94 w = h / template.getHeight() * template.getWidth(); 103 if (scale == 0f) { 104 w = h / template.getHeight() * template.getWidth(); 105 } 106 else { 107 float maxh = h; 108 w = template.getWidth() * scale; 109 h = template.getWidth() * scale; 110 float scaleh = h / maxh; 111 if (scaleh > 1f) { 112 w /= scaleh; 113 h /= scaleh; 114 } 115 } 95 116 } 96 117 } else { 97 118 if (h == 0.0f) { 98 h = w / template.getWidth() * template.getHeight(); 119 if (scale == 0f) { 120 h = w / template.getWidth() * template.getHeight(); 121 } 122 else { 123 float maxw = w; 124 w = template.getWidth() * scale; 125 h = template.getWidth() * scale; 126 float scalew = w / maxw; 127 if (scalew > 1f) { 128 w /= scalew; 129 h /= scalew; 130 } 131 } 132 } 133 else { 134 float maxw = w; 135 float maxh = h; 136 w = template.getWidth() * scale; 137 h = template.getWidth() * scale; 138 float scalew = w / maxw; 139 float scaleh = h / maxh; 140 float maxscale = Math.max(scalew, scaleh); 141 if (maxscale > 1f) { 142 w /= maxscale; 143 h /= maxscale; 144 } 99 145 } 100 146 } … … 437 483 438 484 public static Chunk createImageChunk(RenderingContext context, double maxWidth, double maxHeight, URI url, float rotation) throws DocumentException { 439 final Image image = createImage(context, maxWidth, maxHeight, url, rotation); 485 return createImageChunk(context, maxWidth, maxHeight, 0f, url, rotation); 486 } 487 public static Chunk createImageChunk(RenderingContext context, double maxWidth, double maxHeight, float scale, URI url, float rotation) throws DocumentException { 488 final Image image = createImage(context, maxWidth, maxHeight, scale, url, rotation); 440 489 return new Chunk(image, 0f, 0f, true); 441 490 } 442 491 443 492 public static Image createImage(RenderingContext context, double maxWidth, double maxHeight, URI url, float rotation) throws DocumentException { 493 return createImage(context, maxWidth, maxHeight, 0f, url, rotation); 494 } 495 public static Image createImage(RenderingContext context, double maxWidth, double maxHeight, float scale, URI url, float rotation) throws DocumentException { 444 496 final Image image; 445 497 try { 446 image = getImage(context, url, (float) maxWidth, (float) maxHeight );498 image = getImage(context, url, (float) maxWidth, (float) maxHeight, scale); 447 499 } catch (IOException e) { 448 500 throw new InvalidValueException("url", url.toString(), e); -
print/trunk/src/main/java/org/mapfish/print/config/Config.java
r3827 r3831 396 396 String name = null; 397 397 if(layout != null) { 398 name = PDFUtils.getValueFromString(layout.getOutputFilename()); // get the string if it has ${now} or ${now DATEFORMAT} in it 398 name = layout.getOutputFilename(); 399 if (name != null) { 400 name = PDFUtils.getValueFromString(name); // get the string if it has ${now} or ${now DATEFORMAT} in it 401 } 399 402 } 400 403 return name == null ? outputFilename : name; -
print/trunk/src/main/java/org/mapfish/print/config/layout/LegendsBlock.java
r3826 r3831 46 46 public static final Logger LOGGER = Logger.getLogger(LegendsBlock.class); 47 47 48 private double maxIconWidth = 0; 49 private double maxIconHeight = 8; 48 private double maxIconWidth = 0; // 0 mean disable 49 private double maxIconHeight = 8; // 0 mean disable 50 private float scale = 0; // 0 mean disable 51 private boolean inline = true; 50 52 private double classIndentation = 20; 51 private doublelayerSpace = 5;52 private doubleclassSpace = 2;53 private float layerSpace = 5; 54 private float classSpace = 2; 53 55 54 56 private String layerFont = "Helvetica"; … … 69 71 for (int i = 0; i < legends.size(); ++i) { 70 72 PJsonObject layer = legends.getJSONObject(i); 71 final PdfPCell cell = createLine(context, 0.0, layer, layerPdfFont, params); 72 if (i > 0) { 73 cell.setPaddingTop((float) layerSpace); 74 } 75 table.addCell(cell); 73 createLine(context, 0.0, layer, layerPdfFont, params, table, i == 0 ? layerSpace : 0); 76 74 77 75 PJsonArray classes = layer.getJSONArray("classes"); 78 76 for (int j = 0; j < classes.size(); ++j) { 79 77 PJsonObject clazz = classes.getJSONObject(j); 80 final PdfPCell classCell = createLine(context, classIndentation, clazz, classPdfFont, params); 81 classCell.setPaddingTop((float) classSpace); 82 table.addCell(classCell); 78 createLine(context, classIndentation, clazz, classPdfFont, params, table, classSpace); 83 79 } 84 80 } … … 88 84 } 89 85 90 private PdfPCell createLine(RenderingContext context, double indent, PJsonObject node, Font pdfFont, PJsonObject params) throws DocumentException { 86 private void createLine(RenderingContext context, double indent, PJsonObject node, Font pdfFont, PJsonObject params, 87 PdfPTable table, float lineSpace) throws DocumentException { 91 88 final String name = node.getString("name"); 92 89 final String icon = node.optString("icon"); 93 90 final PJsonArray icons = node.optJSONArray("icons"); 94 91 95 final Paragraph result = new Paragraph(); 96 result.setFont(pdfFont); 92 Paragraph result = new Paragraph(); 97 93 if (icon != null) { 98 try { 99 if (icon.indexOf("image%2Fsvg%2Bxml") != -1) { // TaODO: make this cleaner 100 result.add(PDFUtils.createImageChunkFromSVG(context, icon, maxIconWidth, maxIconHeight)); 101 } else { 102 result.add(PDFUtils.createImageChunk(context, maxIconWidth, maxIconHeight, URI.create(icon), 0.0f)); 103 } 104 result.add(" "); 105 } catch (IOException ioe) { 94 try { 95 if (icon.indexOf("image%2Fsvg%2Bxml") != -1) { // TODO: make this cleaner 96 result.add(PDFUtils.createImageChunkFromSVG(context, icon, maxIconWidth, maxIconHeight)); 97 } else { 98 result.add(PDFUtils.createImageChunk(context, maxIconWidth, maxIconHeight, URI.create(icon), 0f)); 99 } 100 if (!inline) { 101 addCell(context, indent, params, table, lineSpace, result); 102 result = new Paragraph(); 103 result.setFont(pdfFont); 104 } 105 else { 106 result.add(" "); 107 } 108 } catch (IOException ioe) { 106 109 LOGGER.warn("Failed to load " + icon + " with " + ioe.getMessage()); 107 110 } catch (InvalidValueException e) { … … 113 116 String iconItem = icons.getString(i); 114 117 try { 115 if (iconItem.indexOf("image%2Fsvg%2Bxml") != -1) { // T aODO: make this cleaner116 result.add(PDFUtils.createImageChunkFromSVG(context, iconItem, maxIconWidth, maxIconHeight));118 if (iconItem.indexOf("image%2Fsvg%2Bxml") != -1) { // TODO: make this cleaner 119 result.add(PDFUtils.createImageChunkFromSVG(context, iconItem, maxIconWidth, maxIconHeight)); 117 120 } else { 118 result.add(PDFUtils.createImageChunk(context, maxIconWidth, maxIconHeight, URI.create(iconItem), 0.0f));121 result.add(PDFUtils.createImageChunk(context, maxIconWidth, maxIconHeight, scale, URI.create(iconItem), 0f)); 119 122 } 120 result.add(" "); 123 if (!inline) { 124 addCell(context, indent, params, table, 0, result); 125 result = new Paragraph(); 126 result.setFont(pdfFont); 127 } 128 else { 129 result.add(" "); 130 } 121 131 } catch (IOException ioe) { 122 132 LOGGER.warn("Failed to load " + iconItem + " with " + ioe.getMessage()); … … 126 136 } 127 137 } 128 129 138 final PdfPCell cell = new PdfPCell(result); 130 139 cell.setBorder(PdfPCell.NO_BORDER); … … 132 141 cell.setPaddingLeft((float) indent); 133 142 143 result.setFont(pdfFont); 134 144 result.add(name); 135 145 … … 137 147 cell.setBackgroundColor(getBackgroundColorVal(context, params)); 138 148 } 139 140 return cell; 141 } 142 149 table.addCell(cell); 150 } 151 152 private void addCell(RenderingContext context, double indent, PJsonObject params, PdfPTable table, 153 float lineSpace, final Paragraph result) { 154 final PdfPCell cell = new PdfPCell(result); 155 cell.setBorder(PdfPCell.NO_BORDER); 156 cell.setPadding(0f); 157 cell.setPaddingLeft((float) indent); 158 159 if (getBackgroundColorVal(context, params) != null) { 160 cell.setBackgroundColor(getBackgroundColorVal(context, params)); 161 } 162 163 cell.setPaddingTop(lineSpace); 164 table.addCell(cell); 165 } 166 167 public void setDefaultScale(double scale) { 168 this.scale = (float)scale; 169 if (scale < 0.0) throw new InvalidValueException("scale", scale); 170 } 171 172 public void setInline(String inline) { 173 this.inline = "true".equalsIgnoreCase(inline); 174 if (!inline.equalsIgnoreCase("true") || !inline.equalsIgnoreCase("false")) throw new InvalidValueException("inline", inline); 175 } 176 143 177 public void setMaxIconWidth(double maxIconWidth) { 144 178 this.maxIconWidth = maxIconWidth; … … 178 212 179 213 public void setLayerSpace(double layerSpace) { 180 this.layerSpace = layerSpace;214 this.layerSpace = (float)layerSpace; 181 215 if (layerSpace < 0.0) throw new InvalidValueException("layerSpace", layerSpace); 182 216 } 183 217 184 218 public void setClassSpace(double classSpace) { 185 this.classSpace = classSpace;219 this.classSpace = (float)classSpace; 186 220 if (classSpace < 0.0) throw new InvalidValueException("classSpace", classSpace); 187 221 }
