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