cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % PPPP AAA N N GGGG OOO % |
| 7 | % P P A A NN N G O O % |
cristy | fde4ac3 | 2012-03-15 11:25:35 +0000 | [diff] [blame] | 8 | % PPPP AAAAA N N N G GGG O O % |
| 9 | % P M A A N NN G G O O % |
| 10 | % P A A N N GGGG OOO % |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 11 | % % |
| 12 | % % |
cristy | fde4ac3 | 2012-03-15 11:25:35 +0000 | [diff] [blame] | 13 | % Read Pango Markup Language Format % |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
cristy | fde4ac3 | 2012-03-15 11:25:35 +0000 | [diff] [blame] | 17 | % March 2012 % |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 18 | % % |
| 19 | % % |
cristy | 45ef08f | 2012-12-07 13:13:34 +0000 | [diff] [blame] | 20 | % Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization % |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
| 26 | % http://www.imagemagick.org/script/license.php % |
| 27 | % % |
| 28 | % Unless required by applicable law or agreed to in writing, software % |
| 29 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 30 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 31 | % See the License for the specific language governing permissions and % |
| 32 | % limitations under the License. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | */ |
| 38 | |
| 39 | /* |
| 40 | Include declarations. |
| 41 | */ |
| 42 | #include "MagickCore/studio.h" |
| 43 | #include "MagickCore/annotate.h" |
| 44 | #include "MagickCore/blob.h" |
| 45 | #include "MagickCore/blob-private.h" |
| 46 | #include "MagickCore/composite-private.h" |
| 47 | #include "MagickCore/draw.h" |
| 48 | #include "MagickCore/draw-private.h" |
| 49 | #include "MagickCore/exception.h" |
| 50 | #include "MagickCore/exception-private.h" |
| 51 | #include "MagickCore/image.h" |
| 52 | #include "MagickCore/image-private.h" |
| 53 | #include "MagickCore/list.h" |
| 54 | #include "MagickCore/magick.h" |
cristy | fde4ac3 | 2012-03-15 11:25:35 +0000 | [diff] [blame] | 55 | #include "MagickCore/memory_.h" |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 56 | #include "MagickCore/module.h" |
| 57 | #include "MagickCore/monitor.h" |
| 58 | #include "MagickCore/monitor-private.h" |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 59 | #include "MagickCore/option.h" |
cristy | fde4ac3 | 2012-03-15 11:25:35 +0000 | [diff] [blame] | 60 | #include "MagickCore/pixel-accessor.h" |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 61 | #include "MagickCore/property.h" |
| 62 | #include "MagickCore/quantum-private.h" |
| 63 | #include "MagickCore/static.h" |
| 64 | #include "MagickCore/string_.h" |
| 65 | #include "MagickCore/string-private.h" |
cristy | e40005d | 2012-03-23 12:18:45 +0000 | [diff] [blame] | 66 | #include "MagickCore/token.h" |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 67 | #include "MagickCore/utility.h" |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 68 | #if defined(MAGICKCORE_PANGOCAIRO_DELEGATE) |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 69 | #include <pango/pango.h> |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 70 | #include <pango/pangocairo.h> |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 71 | #include <pango/pango-features.h> |
| 72 | #endif |
| 73 | |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 74 | #if defined(MAGICKCORE_PANGOCAIRO_DELEGATE) |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 75 | /* |
| 76 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 77 | % % |
| 78 | % % |
| 79 | % % |
| 80 | % R e a d P A N G O I m a g e % |
| 81 | % % |
| 82 | % % |
| 83 | % % |
| 84 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 85 | % |
cristy | fde4ac3 | 2012-03-15 11:25:35 +0000 | [diff] [blame] | 86 | % ReadPANGOImage() reads an image in the Pango Markup Language Format. |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 87 | % |
| 88 | % The format of the ReadPANGOImage method is: |
| 89 | % |
| 90 | % Image *ReadPANGOImage(const ImageInfo *image_info, |
| 91 | % ExceptionInfo *exception) |
| 92 | % |
| 93 | % A description of each parameter follows: |
| 94 | % |
| 95 | % o image_info: the image info. |
| 96 | % |
| 97 | % o exception: return any errors or warnings in this structure. |
| 98 | % |
| 99 | */ |
cristy | fde4ac3 | 2012-03-15 11:25:35 +0000 | [diff] [blame] | 100 | static Image *ReadPANGOImage(const ImageInfo *image_info, |
| 101 | ExceptionInfo *exception) |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 102 | { |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 103 | cairo_font_options_t |
| 104 | *font_options; |
| 105 | |
| 106 | cairo_surface_t |
| 107 | *surface; |
| 108 | |
cristy | fde4ac3 | 2012-03-15 11:25:35 +0000 | [diff] [blame] | 109 | char |
| 110 | *caption, |
| 111 | *property; |
| 112 | |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 113 | cairo_t |
cristy | ab1975c | 2012-03-27 01:34:11 +0000 | [diff] [blame] | 114 | *cairo_image; |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 115 | |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 116 | const char |
| 117 | *option; |
| 118 | |
cristy | fde4ac3 | 2012-03-15 11:25:35 +0000 | [diff] [blame] | 119 | DrawInfo |
| 120 | *draw_info; |
| 121 | |
cristy | fde4ac3 | 2012-03-15 11:25:35 +0000 | [diff] [blame] | 122 | Image |
| 123 | *image; |
| 124 | |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 125 | MagickBooleanType |
| 126 | status; |
| 127 | |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 128 | PangoAlignment |
| 129 | align; |
| 130 | |
| 131 | PangoContext |
| 132 | *context; |
| 133 | |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 134 | PangoFontMap |
| 135 | *fontmap; |
| 136 | |
| 137 | PangoGravity |
| 138 | gravity; |
| 139 | |
| 140 | PangoLayout |
| 141 | *layout; |
| 142 | |
| 143 | PangoRectangle |
| 144 | extent; |
| 145 | |
| 146 | PixelInfo |
| 147 | fill_color; |
| 148 | |
| 149 | RectangleInfo |
| 150 | page; |
| 151 | |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 152 | register unsigned char |
| 153 | *p; |
| 154 | |
cristy | ab1975c | 2012-03-27 01:34:11 +0000 | [diff] [blame] | 155 | size_t |
| 156 | stride; |
| 157 | |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 158 | ssize_t |
| 159 | y; |
| 160 | |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 161 | unsigned char |
| 162 | *pixels; |
| 163 | |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 164 | /* |
cristy | fde4ac3 | 2012-03-15 11:25:35 +0000 | [diff] [blame] | 165 | Initialize Image structure. |
| 166 | */ |
| 167 | assert(image_info != (const ImageInfo *) NULL); |
| 168 | assert(image_info->signature == MagickSignature); |
| 169 | if (image_info->debug != MagickFalse) |
| 170 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 171 | image_info->filename); |
| 172 | assert(exception != (ExceptionInfo *) NULL); |
| 173 | assert(exception->signature == MagickSignature); |
| 174 | image=AcquireImage(image_info,exception); |
| 175 | (void) ResetImagePage(image,"0x0+0+0"); |
| 176 | /* |
cristy | c0732c4 | 2012-03-20 19:28:35 +0000 | [diff] [blame] | 177 | Format caption. |
| 178 | */ |
| 179 | option=GetImageOption(image_info,"filename"); |
| 180 | if (option == (const char *) NULL) |
| 181 | property=InterpretImageProperties(image_info,image,image_info->filename, |
| 182 | exception); |
| 183 | else |
| 184 | if (LocaleNCompare(option,"pango:",6) == 0) |
| 185 | property=InterpretImageProperties(image_info,image,option+6,exception); |
| 186 | else |
| 187 | property=InterpretImageProperties(image_info,image,option,exception); |
| 188 | (void) SetImageProperty(image,"caption",property,exception); |
| 189 | property=DestroyString(property); |
| 190 | caption=ConstantString(GetImageProperty(image,"caption",exception)); |
| 191 | /* |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 192 | Get context. |
| 193 | */ |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 194 | fontmap=pango_cairo_font_map_new(); |
| 195 | pango_cairo_font_map_set_resolution(PANGO_CAIRO_FONT_MAP(fontmap), |
cristy | 2d67731 | 2013-01-02 19:19:21 +0000 | [diff] [blame] | 196 | image->resolution.x == 0.0 ? 90.0 : image->resolution.x); |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 197 | font_options=cairo_font_options_create(); |
cristy | bafa870 | 2012-03-15 00:20:24 +0000 | [diff] [blame] | 198 | option=GetImageOption(image_info,"pango:hinting"); |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 199 | if (option != (const char *) NULL) |
| 200 | { |
| 201 | if (LocaleCompare(option,"none") != 0) |
| 202 | cairo_font_options_set_hint_style(font_options,CAIRO_HINT_STYLE_NONE); |
| 203 | if (LocaleCompare(option,"full") != 0) |
| 204 | cairo_font_options_set_hint_style(font_options,CAIRO_HINT_STYLE_FULL); |
| 205 | } |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 206 | context=pango_font_map_create_context(fontmap); |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 207 | pango_cairo_context_set_font_options(context,font_options); |
cristy | ab1975c | 2012-03-27 01:34:11 +0000 | [diff] [blame] | 208 | cairo_font_options_destroy(font_options); |
cristy | bafa870 | 2012-03-15 00:20:24 +0000 | [diff] [blame] | 209 | option=GetImageOption(image_info,"pango:language"); |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 210 | if (option != (const char *) NULL) |
| 211 | pango_context_set_language(context,pango_language_from_string(option)); |
cristy | fde4ac3 | 2012-03-15 11:25:35 +0000 | [diff] [blame] | 212 | draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL); |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 213 | pango_context_set_base_dir(context,draw_info->direction == |
| 214 | RightToLeftDirection ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR); |
| 215 | switch (draw_info->gravity) |
| 216 | { |
cristy | 58845e3 | 2012-03-27 15:44:05 +0000 | [diff] [blame] | 217 | case NorthGravity: |
| 218 | { |
| 219 | gravity=PANGO_GRAVITY_NORTH; |
| 220 | break; |
| 221 | } |
| 222 | case NorthWestGravity: |
| 223 | case WestGravity: |
| 224 | case SouthWestGravity: |
| 225 | { |
| 226 | gravity=PANGO_GRAVITY_WEST; |
| 227 | break; |
| 228 | } |
| 229 | case NorthEastGravity: |
| 230 | case EastGravity: |
| 231 | case SouthEastGravity: |
| 232 | { |
| 233 | gravity=PANGO_GRAVITY_EAST; |
| 234 | break; |
| 235 | } |
| 236 | case SouthGravity: |
| 237 | { |
| 238 | gravity=PANGO_GRAVITY_SOUTH; |
| 239 | break; |
| 240 | } |
| 241 | default: |
| 242 | { |
| 243 | gravity=PANGO_GRAVITY_AUTO; |
| 244 | break; |
| 245 | } |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 246 | } |
| 247 | pango_context_set_base_gravity(context,gravity); |
cristy | bafa870 | 2012-03-15 00:20:24 +0000 | [diff] [blame] | 248 | option=GetImageOption(image_info,"pango:gravity-hint"); |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 249 | if (option != (const char *) NULL) |
| 250 | { |
| 251 | if (LocaleCompare(option,"line") == 0) |
| 252 | pango_context_set_gravity_hint(context,PANGO_GRAVITY_HINT_LINE); |
| 253 | if (LocaleCompare(option,"natural") == 0) |
| 254 | pango_context_set_gravity_hint(context,PANGO_GRAVITY_HINT_NATURAL); |
| 255 | if (LocaleCompare(option,"strong") == 0) |
| 256 | pango_context_set_gravity_hint(context,PANGO_GRAVITY_HINT_STRONG); |
| 257 | } |
| 258 | /* |
| 259 | Configure layout. |
| 260 | */ |
| 261 | layout=pango_layout_new(context); |
cristy | bafa870 | 2012-03-15 00:20:24 +0000 | [diff] [blame] | 262 | option=GetImageOption(image_info,"pango:auto-dir"); |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 263 | if (option != (const char *) NULL) |
| 264 | pango_layout_set_auto_dir(layout,1); |
cristy | bafa870 | 2012-03-15 00:20:24 +0000 | [diff] [blame] | 265 | option=GetImageOption(image_info,"pango:ellipsize"); |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 266 | if (option != (const char *) NULL) |
| 267 | { |
| 268 | if (LocaleCompare(option,"end") == 0) |
| 269 | pango_layout_set_ellipsize(layout,PANGO_ELLIPSIZE_END); |
| 270 | if (LocaleCompare(option,"middle") == 0) |
| 271 | pango_layout_set_ellipsize(layout,PANGO_ELLIPSIZE_MIDDLE); |
| 272 | if (LocaleCompare(option,"none") == 0) |
| 273 | pango_layout_set_ellipsize(layout,PANGO_ELLIPSIZE_NONE); |
| 274 | if (LocaleCompare(option,"start") == 0) |
| 275 | pango_layout_set_ellipsize(layout,PANGO_ELLIPSIZE_START); |
| 276 | } |
cristy | bafa870 | 2012-03-15 00:20:24 +0000 | [diff] [blame] | 277 | option=GetImageOption(image_info,"pango:justify"); |
anthony | 7bcfe7f | 2012-03-30 14:01:22 +0000 | [diff] [blame] | 278 | if (IfMagickTrue(IsStringTrue(option))) |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 279 | pango_layout_set_justify(layout,1); |
cristy | bafa870 | 2012-03-15 00:20:24 +0000 | [diff] [blame] | 280 | option=GetImageOption(image_info,"pango:single-paragraph"); |
anthony | 7bcfe7f | 2012-03-30 14:01:22 +0000 | [diff] [blame] | 281 | if (IfMagickTrue(IsStringTrue(option))) |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 282 | pango_layout_set_single_paragraph_mode(layout,1); |
cristy | bafa870 | 2012-03-15 00:20:24 +0000 | [diff] [blame] | 283 | option=GetImageOption(image_info,"pango:wrap"); |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 284 | if (option != (const char *) NULL) |
| 285 | { |
| 286 | if (LocaleCompare(option,"char") == 0) |
| 287 | pango_layout_set_wrap(layout,PANGO_WRAP_CHAR); |
| 288 | if (LocaleCompare(option,"word") == 0) |
| 289 | pango_layout_set_wrap(layout,PANGO_WRAP_WORD); |
| 290 | if (LocaleCompare(option,"word-char") == 0) |
| 291 | pango_layout_set_wrap(layout,PANGO_WRAP_WORD_CHAR); |
| 292 | } |
cristy | bafa870 | 2012-03-15 00:20:24 +0000 | [diff] [blame] | 293 | option=GetImageOption(image_info,"pango:indent"); |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 294 | if (option != (const char *) NULL) |
cristy | 22fd9d3 | 2012-03-19 11:50:33 +0000 | [diff] [blame] | 295 | pango_layout_set_indent(layout,(int) ((StringToLong(option)* |
cristy | 2d67731 | 2013-01-02 19:19:21 +0000 | [diff] [blame] | 296 | (image->resolution.x == 0.0 ? 90.0 : image->resolution.x)*PANGO_SCALE+36)/ |
| 297 | 90.0+0.5)); |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 298 | switch (draw_info->align) |
| 299 | { |
| 300 | case CenterAlign: align=PANGO_ALIGN_CENTER; break; |
| 301 | case RightAlign: align=PANGO_ALIGN_RIGHT; break; |
| 302 | case LeftAlign: align=PANGO_ALIGN_LEFT; break; |
| 303 | default: |
| 304 | { |
| 305 | if (draw_info->gravity == CenterGravity) |
cristy | fde4ac3 | 2012-03-15 11:25:35 +0000 | [diff] [blame] | 306 | { |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 307 | align=PANGO_ALIGN_CENTER; |
| 308 | break; |
| 309 | } |
| 310 | align=PANGO_ALIGN_LEFT; |
| 311 | break; |
| 312 | } |
| 313 | } |
| 314 | if ((align != PANGO_ALIGN_CENTER) && |
| 315 | (draw_info->direction == RightToLeftDirection)) |
| 316 | align=(PangoAlignment) (PANGO_ALIGN_LEFT+PANGO_ALIGN_RIGHT-align); |
| 317 | pango_layout_set_alignment(layout,align); |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 318 | if (draw_info->font != (char *) NULL) |
| 319 | { |
| 320 | PangoFontDescription |
| 321 | *description; |
| 322 | |
| 323 | /* |
| 324 | Set font. |
| 325 | */ |
| 326 | description=pango_font_description_from_string(draw_info->font); |
| 327 | pango_font_description_set_size(description,(int) (PANGO_SCALE* |
| 328 | draw_info->pointsize+0.5)); |
| 329 | pango_layout_set_font_description(layout,description); |
| 330 | pango_font_description_free(description); |
| 331 | } |
cristy | bafa870 | 2012-03-15 00:20:24 +0000 | [diff] [blame] | 332 | option=GetImageOption(image_info,"pango:markup"); |
cristy | f3dbd11 | 2012-04-11 21:05:40 +0000 | [diff] [blame] | 333 | if ((option != (const char *) NULL) && (IsStringTrue(option) == MagickFalse)) |
cristy | fde4ac3 | 2012-03-15 11:25:35 +0000 | [diff] [blame] | 334 | pango_layout_set_text(layout,caption,-1); |
cristy | 4d84e4a | 2012-03-19 11:27:53 +0000 | [diff] [blame] | 335 | else |
| 336 | { |
| 337 | GError |
| 338 | *error; |
| 339 | |
| 340 | error=(GError *) NULL; |
| 341 | if (pango_parse_markup(caption,-1,0,NULL,NULL,NULL,&error) == 0) |
| 342 | (void) ThrowMagickException(exception,GetMagickModule(),CoderError, |
| 343 | error->message,"`%s'",image_info->filename); |
| 344 | pango_layout_set_markup(layout,caption,-1); |
| 345 | } |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 346 | pango_layout_context_changed(layout); |
| 347 | page.x=0; |
| 348 | page.y=0; |
| 349 | if (image_info->page != (char *) NULL) |
| 350 | (void) ParseAbsoluteGeometry(image_info->page,&page); |
| 351 | if (image->columns == 0) |
| 352 | { |
cristy | 8592b05 | 2013-02-07 01:24:54 +0000 | [diff] [blame^] | 353 | pango_layout_get_extents(layout,NULL,&extent); |
cristy | 9171f11 | 2013-01-02 19:59:13 +0000 | [diff] [blame] | 354 | image->columns=(extent.x+extent.width+PANGO_SCALE/2)/PANGO_SCALE+2*page.x; |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 355 | } |
| 356 | else |
| 357 | { |
| 358 | image->columns-=2*page.x; |
cristy | 22fd9d3 | 2012-03-19 11:50:33 +0000 | [diff] [blame] | 359 | pango_layout_set_width(layout,(int) ((PANGO_SCALE*image->columns* |
cristy | 910b796 | 2013-01-06 14:30:18 +0000 | [diff] [blame] | 360 | (image->resolution.x == 0.0 ? 90.0 : image->resolution.x)+45.0)/90.0+ |
cristy | 67cd01f | 2013-01-02 13:49:56 +0000 | [diff] [blame] | 361 | 0.5)); |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 362 | } |
| 363 | if (image->rows == 0) |
| 364 | { |
cristy | 8592b05 | 2013-02-07 01:24:54 +0000 | [diff] [blame^] | 365 | pango_layout_get_extents(layout,NULL,&extent); |
cristy | 9171f11 | 2013-01-02 19:59:13 +0000 | [diff] [blame] | 366 | image->rows=(extent.y+extent.height+PANGO_SCALE/2)/PANGO_SCALE+2*page.y; |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 367 | } |
| 368 | else |
| 369 | { |
| 370 | image->rows-=2*page.y; |
cristy | 22fd9d3 | 2012-03-19 11:50:33 +0000 | [diff] [blame] | 371 | pango_layout_set_height(layout,(int) ((PANGO_SCALE*image->rows* |
cristy | 910b796 | 2013-01-06 14:30:18 +0000 | [diff] [blame] | 372 | (image->resolution.y == 0.0 ? 90.0 : image->resolution.y)+45.0)/90.0+ |
cristy | 67cd01f | 2013-01-02 13:49:56 +0000 | [diff] [blame] | 373 | 0.5)); |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 374 | } |
| 375 | /* |
cristy | ba27530 | 2012-03-27 14:42:23 +0000 | [diff] [blame] | 376 | Render markup. |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 377 | */ |
cristy | ab1975c | 2012-03-27 01:34:11 +0000 | [diff] [blame] | 378 | stride=(size_t) cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, |
| 379 | image->columns); |
cristy | e5dc028 | 2012-04-09 19:07:44 +0000 | [diff] [blame] | 380 | pixels=(unsigned char *) AcquireQuantumMemory(image->rows,stride* |
cristy | ab1975c | 2012-03-27 01:34:11 +0000 | [diff] [blame] | 381 | sizeof(*pixels)); |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 382 | if (pixels == (unsigned char *) NULL) |
cristy | ab1975c | 2012-03-27 01:34:11 +0000 | [diff] [blame] | 383 | { |
| 384 | draw_info=DestroyDrawInfo(draw_info); |
| 385 | caption=DestroyString(caption); |
| 386 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 387 | } |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 388 | surface=cairo_image_surface_create_for_data(pixels,CAIRO_FORMAT_ARGB32, |
cristy | ab1975c | 2012-03-27 01:34:11 +0000 | [diff] [blame] | 389 | image->columns,image->rows,stride); |
| 390 | cairo_image=cairo_create(surface); |
cristy | ba27530 | 2012-03-27 14:42:23 +0000 | [diff] [blame] | 391 | cairo_set_operator(cairo_image,CAIRO_OPERATOR_CLEAR); |
cristy | ab1975c | 2012-03-27 01:34:11 +0000 | [diff] [blame] | 392 | cairo_paint(cairo_image); |
| 393 | cairo_set_operator(cairo_image,CAIRO_OPERATOR_OVER); |
cristy | 973b85f | 2012-03-27 14:56:21 +0000 | [diff] [blame] | 394 | cairo_translate(cairo_image,page.x,page.y); |
cristy | ab1975c | 2012-03-27 01:34:11 +0000 | [diff] [blame] | 395 | pango_cairo_show_layout(cairo_image,layout); |
cristy | ab1975c | 2012-03-27 01:34:11 +0000 | [diff] [blame] | 396 | cairo_destroy(cairo_image); |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 397 | cairo_surface_destroy(surface); |
cristy | ba27530 | 2012-03-27 14:42:23 +0000 | [diff] [blame] | 398 | g_object_unref(layout); |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 399 | g_object_unref(fontmap); |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 400 | /* |
cristy | ab1975c | 2012-03-27 01:34:11 +0000 | [diff] [blame] | 401 | Convert surface to image. |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 402 | */ |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 403 | (void) SetImageBackgroundColor(image,exception); |
| 404 | p=pixels; |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 405 | GetPixelInfo(image,&fill_color); |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 406 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 407 | { |
cristy | ba27530 | 2012-03-27 14:42:23 +0000 | [diff] [blame] | 408 | register Quantum |
| 409 | *q; |
| 410 | |
cristy | ab1975c | 2012-03-27 01:34:11 +0000 | [diff] [blame] | 411 | register ssize_t |
| 412 | x; |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 413 | |
| 414 | q=GetAuthenticPixels(image,0,y,image->columns,1,exception); |
| 415 | if (q == (Quantum *) NULL) |
| 416 | break; |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 417 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 418 | { |
cristy | ab1975c | 2012-03-27 01:34:11 +0000 | [diff] [blame] | 419 | double |
| 420 | gamma; |
| 421 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 422 | fill_color.blue=(double) ScaleCharToQuantum(*p++); |
| 423 | fill_color.green=(double) ScaleCharToQuantum(*p++); |
| 424 | fill_color.red=(double) ScaleCharToQuantum(*p++); |
| 425 | fill_color.alpha=(double) ScaleCharToQuantum(*p++); |
cristy | ab1975c | 2012-03-27 01:34:11 +0000 | [diff] [blame] | 426 | /* |
| 427 | Disassociate alpha. |
| 428 | */ |
| 429 | gamma=1.0-QuantumScale*fill_color.alpha; |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 430 | gamma=PerceptibleReciprocal(gamma); |
cristy | ab1975c | 2012-03-27 01:34:11 +0000 | [diff] [blame] | 431 | fill_color.blue*=gamma; |
| 432 | fill_color.green*=gamma; |
| 433 | fill_color.red*=gamma; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 434 | CompositePixelOver(image,&fill_color,fill_color.alpha,q,(double) |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 435 | GetPixelAlpha(image,q),q); |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 436 | q+=GetPixelChannels(image); |
| 437 | } |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 438 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 439 | break; |
| 440 | if (image->previous == (Image *) NULL) |
| 441 | { |
| 442 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
| 443 | image->rows); |
| 444 | if (status == MagickFalse) |
| 445 | break; |
| 446 | } |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 447 | } |
| 448 | /* |
| 449 | Relinquish resources. |
| 450 | */ |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 451 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
cristy | fde4ac3 | 2012-03-15 11:25:35 +0000 | [diff] [blame] | 452 | draw_info=DestroyDrawInfo(draw_info); |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 453 | caption=DestroyString(caption); |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 454 | return(GetFirstImageInList(image)); |
| 455 | } |
cristy | fde4ac3 | 2012-03-15 11:25:35 +0000 | [diff] [blame] | 456 | #endif |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 457 | |
| 458 | /* |
| 459 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 460 | % % |
| 461 | % % |
| 462 | % % |
| 463 | % R e g i s t e r P A N G O I m a g e % |
| 464 | % % |
| 465 | % % |
| 466 | % % |
| 467 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 468 | % |
cristy | fde4ac3 | 2012-03-15 11:25:35 +0000 | [diff] [blame] | 469 | % RegisterPANGOImage() adds attributes for the Pango Markup Language format to |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 470 | % the list of supported formats. The attributes include the image format |
| 471 | % tag, a method to read and/or write the format, whether the format |
| 472 | % supports the saving of more than one frame to the same file or blob, |
| 473 | % whether the format supports native in-memory I/O, and a brief |
| 474 | % description of the format. |
| 475 | % |
| 476 | % The format of the RegisterPANGOImage method is: |
| 477 | % |
| 478 | % size_t RegisterPANGOImage(void) |
| 479 | % |
| 480 | */ |
| 481 | ModuleExport size_t RegisterPANGOImage(void) |
| 482 | { |
| 483 | char |
| 484 | version[MaxTextExtent]; |
| 485 | |
| 486 | MagickInfo |
| 487 | *entry; |
| 488 | |
| 489 | *version='\0'; |
| 490 | #if defined(PANGO_VERSION_STRING) |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 491 | (void) FormatLocaleString(version,MaxTextExtent,"Pangocairo %s", |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 492 | PANGO_VERSION_STRING); |
| 493 | #endif |
| 494 | entry=SetMagickInfo("PANGO"); |
cristy | 19642b0 | 2012-03-26 19:33:21 +0000 | [diff] [blame] | 495 | #if defined(MAGICKCORE_PANGOCAIRO_DELEGATE) |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 496 | entry->decoder=(DecodeImageHandler *) ReadPANGOImage; |
cristy | fde4ac3 | 2012-03-15 11:25:35 +0000 | [diff] [blame] | 497 | #endif |
| 498 | entry->description=ConstantString("Pango Markup Language"); |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 499 | if (*version != '\0') |
| 500 | entry->version=ConstantString(version); |
| 501 | entry->adjoin=MagickFalse; |
| 502 | entry->module=ConstantString("PANGO"); |
| 503 | (void) RegisterMagickInfo(entry); |
| 504 | return(MagickImageCoderSignature); |
| 505 | } |
| 506 | |
| 507 | /* |
| 508 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 509 | % % |
| 510 | % % |
| 511 | % % |
| 512 | % U n r e g i s t e r P A N G O I m a g e % |
| 513 | % % |
| 514 | % % |
| 515 | % % |
| 516 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 517 | % |
cristy | fde4ac3 | 2012-03-15 11:25:35 +0000 | [diff] [blame] | 518 | % UnregisterPANGOImage() removes format registrations made by the Pango module |
| 519 | % from the list of supported formats. |
cristy | bb06a1a | 2012-03-15 00:16:53 +0000 | [diff] [blame] | 520 | % |
| 521 | % The format of the UnregisterPANGOImage method is: |
| 522 | % |
| 523 | % UnregisterPANGOImage(void) |
| 524 | % |
| 525 | */ |
| 526 | ModuleExport void UnregisterPANGOImage(void) |
| 527 | { |
| 528 | (void) UnregisterMagickInfo("PANGO"); |
| 529 | } |