1 /** 2 * License: 3 * $(TABLE 4 * $(TR $(TD cairoD wrapper/bindings) 5 * $(TD $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0))) 6 * $(TR $(TD $(LINK2 http://cgit.freedesktop.org/cairo/tree/COPYING, _cairo)) 7 * $(TD $(LINK2 http://cgit.freedesktop.org/cairo/tree/COPYING-LGPL-2.1, LGPL 2.1) / 8 * $(LINK2 http://cgit.freedesktop.org/cairo/plain/COPYING-MPL-1.1, MPL 1.1))) 9 * ) 10 * Authors: 11 * $(TABLE 12 * $(TR $(TD Johannes Pfau) $(TD cairoD)) 13 * $(TR $(TD $(LINK2 http://cairographics.org, _cairo team)) $(TD _cairo)) 14 * ) 15 */ 16 /* 17 * Distributed under the Boost Software License, Version 1.0. 18 * (See accompanying file LICENSE_1_0.txt or copy at 19 * http://www.boost.org/LICENSE_1_0.txt) 20 */ 21 module cairo.ps; 22 23 import std.string; 24 import std.conv; 25 26 import cairo.cairo; 27 import cairo.c.cairo; 28 29 static if(CAIRO_HAS_PS_SURFACE) 30 { 31 import cairo.c.ps; 32 33 /// 34 public alias cairo_ps_level_t PSLevel; 35 36 /** 37 * Used to retrieve the list of supported levels. 38 * See $(D PSSurface.restrictToLevel()). 39 */ 40 PSLevel[] getPSLevels() 41 { 42 int num; 43 immutable(cairo_ps_level_t*) levels; 44 cairo_ps_get_levels(&levels, &num); 45 PSLevel[] dlevels; 46 for(int i = 0; i < num; i++) 47 { 48 dlevels ~= levels[i]; 49 } 50 return dlevels; 51 } 52 53 /** 54 * Get the string representation of the given level id. This function 55 * will return NULL if level id isn't valid. See $(D getPSLevels()) 56 * for a way to get the list of valid level ids. 57 */ 58 string PSLevelToString(PSLevel level) 59 { 60 return to!string(cairo_ps_level_to_string(level)); 61 } 62 63 /** 64 * The PostScript surface is used to render cairo graphics to 65 * Adobe PostScript files and is a multi-page vector surface backend. 66 */ 67 public class PSSurface : Surface 68 { 69 public: 70 /** 71 * Create a $(D PSSurface) from a existing $(D cairo_surface_t*). 72 * PSSurface is a garbage collected class. It will call $(D cairo_surface_destroy) 73 * when it gets collected by the GC or when $(D dispose()) is called. 74 * 75 * Warning: 76 * $(D ptr)'s reference count is not increased by this function! 77 * Adjust reference count before calling it if necessary 78 * 79 * $(RED Only use this if you know what your doing! 80 * This function should not be needed for standard cairoD usage.) 81 */ 82 this(cairo_surface_t* ptr) 83 { 84 super(ptr); 85 } 86 87 /** 88 * Creates a PostScript surface of the specified size in 89 * points to be written to filename. 90 * 91 * Note that the size of individual pages of the PostScript 92 * output can vary. See $(D setSize()). 93 * 94 * Params: 95 * width = width of the surface, in points (1 point == 1/72.0 inch) 96 * height = height of the surface, in points (1 point == 1/72.0 inch) 97 */ 98 this(string fileName, double width, double height) 99 { 100 super(cairo_ps_surface_create(toStringz(fileName), width, height)); 101 } 102 103 /** 104 * Creates a PostScript surface of the specified size in 105 * points.This will generate a PSSurface that may be queried and 106 * used as a source, without generating a temporary file. 107 * 108 * Params: 109 * width = width of the surface, in points (1 point == 1/72.0 inch) 110 * height = height of the surface, in points (1 point == 1/72.0 inch) 111 */ 112 this(double width, double height) 113 { 114 this("", width, height); 115 } 116 117 /** 118 * Restricts the generated PostSript file to level. 119 * See $(D getPSLevels()) for a list of available 120 * level values that can be used here. 121 * 122 * This function should only be called before any 123 * drawing operations have been performed on the given 124 * surface. The simplest way to do this is to call this 125 * function immediately after creating the surface. 126 */ 127 void restrictToLevel(PSLevel level) 128 { 129 scope(exit) 130 checkError(); 131 cairo_ps_surface_restrict_to_level(this.nativePointer, level); 132 } 133 134 /** 135 * If eps is true, the PostScript surface will output 136 * Encapsulated PostScript. 137 * 138 * This function should only be called before any drawing 139 * operations have been performed on the current page. 140 * The simplest way to do this is to call this function 141 * immediately after creating the surface. An Encapsulated 142 * PostScript file should never contain more than one page. 143 */ 144 void setEPS(bool eps) 145 { 146 scope(exit) 147 checkError(); 148 cairo_ps_surface_set_eps(this.nativePointer, cast(int)eps); 149 } 150 151 /** 152 * Check whether the PostScript surface will output Encapsulated 153 * PostScript. 154 */ 155 bool getEPS(bool eps) 156 { 157 scope(exit) 158 checkError(); 159 return cairo_ps_surface_get_eps(this.nativePointer) ? true : false; 160 } 161 162 /** 163 * hanges the size of a PostScript surface for the current 164 * (and subsequent) pages. 165 * 166 * This function should only be called before any drawing 167 * operations have been performed on the current page. 168 * The simplest way to do this is to call this function 169 * immediately after creating the surface or immediately 170 * after completing a page with either $(D Context.showPage()) 171 * or $(D Context.copyPage()). 172 * 173 * Params: 174 * width = width of the surface, in points (1 point == 1/72.0 inch) 175 * height = height of the surface, in points (1 point == 1/72.0 inch) 176 */ 177 void setSize(double width, double height) 178 { 179 scope(exit) 180 checkError(); 181 return cairo_ps_surface_set_size(this.nativePointer, width, height); 182 } 183 184 /** 185 * This function indicates that subsequent calls to 186 * $(D dscComment()) should direct comments 187 * to the Setup section of the PostScript output. 188 * 189 * This function should be called at most once per surface, 190 * and must be called before any call 191 * to $(D dscBeginPageSetup()) and before 192 * any drawing is performed to the surface. 193 * 194 * See $(D dscComment()) for more details. 195 */ 196 void dscBeginSetup() 197 { 198 scope(exit) 199 checkError(); 200 cairo_ps_surface_dsc_begin_setup(this.nativePointer); 201 } 202 203 /** 204 * This function indicates that subsequent calls to 205 * $(D dscComment()) should direct 206 * comments to the PageSetup section of the PostScript output. 207 * 208 * This function call is only needed for the first 209 * page of a surface. It should be called after any 210 * call to $(D dscBeginSetup()) and 211 * before any drawing is performed to the surface. 212 * 213 * See $(D dscComment()) for more details. 214 */ 215 void dscBeginPageSetup() 216 { 217 scope(exit) 218 checkError(); 219 cairo_ps_surface_dsc_begin_page_setup(this.nativePointer); 220 } 221 222 /** 223 * See 224 * $(LINK http://cairographics.org/manual/cairo-PostScript-Surfaces.html#cairo-ps-surface-dsc-comment) 225 */ 226 void dscComment(string comment) 227 { 228 scope(exit) 229 checkError(); 230 cairo_ps_surface_dsc_comment(this.nativePointer, toStringz(comment)); 231 } 232 } 233 }