tioga 1.17 → 1.18

Sign up to get free protection for your applications and to get access to all the features.
@@ -273,70 +273,96 @@ OBJ_PTR FM_private_create_monochrome_image_data(OBJ_PTR fmkr, OBJ_PTR data,
273
273
  Number_to_int(first_row, &ierr), Number_to_int(last_row, &ierr), Number_to_int(first_column, &ierr), Number_to_int(last_column, &ierr),
274
274
  Number_to_double(boundary, &ierr), reverse != OBJ_FALSE, &ierr);
275
275
  }
276
- OBJ_PTR FM_private_show_jpg(OBJ_PTR fmkr, OBJ_PTR filename,
277
- OBJ_PTR width, OBJ_PTR height, OBJ_PTR image_destination, OBJ_PTR mask_obj_num) { int ierr=0;
278
- c_private_show_jpg(fmkr, Get_FM(fmkr, &ierr), String_Ptr(filename, &ierr),
279
- Number_to_int(width, &ierr), Number_to_int(height, &ierr), image_destination, Number_to_int(mask_obj_num, &ierr), &ierr); RETURN_NIL; }
276
+ OBJ_PTR FM_private_register_jpg(OBJ_PTR fmkr, OBJ_PTR filename,
277
+ OBJ_PTR width, OBJ_PTR height, OBJ_PTR mask_obj_num) { int ierr=0;
278
+ return Integer_New(c_private_register_jpg(fmkr, Get_FM(fmkr, &ierr), String_Ptr(filename, &ierr),
279
+ Number_to_int(width, &ierr), Number_to_int(height, &ierr), Number_to_int(mask_obj_num, &ierr), &ierr));
280
+ }
281
+
282
+ /* Get info on a JPEG file */
283
+ OBJ_PTR FM_jpg_info(OBJ_PTR fmkr, OBJ_PTR filename) {
284
+ int ierr = 0;
285
+ JPG_Info * info = Parse_JPG(String_Ptr(filename, &ierr));
286
+ if(info) {
287
+ OBJ_PTR hsh = Hash_New();
288
+ Hash_Set_Obj(hsh, "width", Integer_New(info->width));
289
+ Hash_Set_Obj(hsh, "height", Integer_New(info->height));
290
+ Hash_Set_Obj(hsh, "jpg", filename);
291
+ Free_JPG(info);
292
+ return hsh;
293
+ }
294
+ else
295
+ return OBJ_NIL;
296
+ }
297
+
298
+ #define Str_Or_NULL(obj, ierr) ((obj == OBJ_NIL) ? NULL : CString_Ptr(obj, ierr))
280
299
 
281
- OBJ_PTR FM_private_show_hls_image(OBJ_PTR fmkr, OBJ_PTR llx, OBJ_PTR lly, OBJ_PTR lrx, OBJ_PTR lry,
282
- OBJ_PTR ulx, OBJ_PTR uly, OBJ_PTR interpolate, OBJ_PTR w, OBJ_PTR h, OBJ_PTR data, OBJ_PTR mask_obj_num)
300
+ OBJ_PTR FM_private_register_hls_image(OBJ_PTR fmkr,
301
+ OBJ_PTR interpolate, OBJ_PTR w, OBJ_PTR h, OBJ_PTR data, OBJ_PTR mask_obj_num, OBJ_PTR components, OBJ_PTR filters)
283
302
  { int ierr=0;
284
- return c_private_show_image(fmkr, Get_FM(fmkr, &ierr), HLS_IMAGE, Number_to_double(llx, &ierr), Number_to_double(lly, &ierr),
285
- Number_to_double(lrx, &ierr), Number_to_double(lry, &ierr),
286
- Number_to_double(ulx, &ierr), Number_to_double(uly, &ierr), (interpolate != OBJ_FALSE), OBJ_FALSE,
303
+ return Integer_New(c_private_register_image(fmkr, Get_FM(fmkr, &ierr), HLS_IMAGE,
304
+ (interpolate != OBJ_FALSE), OBJ_FALSE,
287
305
  Number_to_int(w, &ierr), Number_to_int(h, &ierr), (unsigned char *)String_Ptr(data, &ierr), String_Len(data, &ierr),
288
- OBJ_NIL, OBJ_NIL, OBJ_NIL, OBJ_NIL, Number_to_int(mask_obj_num, &ierr), &ierr);
306
+ OBJ_NIL, OBJ_NIL, OBJ_NIL, OBJ_NIL, Number_to_int(mask_obj_num, &ierr),
307
+ Number_to_int(components, &ierr),
308
+ Str_Or_NULL(filters, &ierr), &ierr));
289
309
  }
290
310
 
291
- OBJ_PTR FM_private_show_rgb_image(OBJ_PTR fmkr, OBJ_PTR llx, OBJ_PTR lly, OBJ_PTR lrx, OBJ_PTR lry,
292
- OBJ_PTR ulx, OBJ_PTR uly, OBJ_PTR interpolate, OBJ_PTR w, OBJ_PTR h, OBJ_PTR data, OBJ_PTR mask_obj_num)
311
+ OBJ_PTR FM_private_register_rgb_image(OBJ_PTR fmkr, OBJ_PTR interpolate, OBJ_PTR w, OBJ_PTR h, OBJ_PTR data, OBJ_PTR mask_obj_num, OBJ_PTR components, OBJ_PTR filters)
293
312
  { int ierr=0;
294
- return c_private_show_image(fmkr, Get_FM(fmkr, &ierr), RGB_IMAGE, Number_to_double(llx, &ierr), Number_to_double(lly, &ierr),
295
- Number_to_double(lrx, &ierr), Number_to_double(lry, &ierr),
296
- Number_to_double(ulx, &ierr), Number_to_double(uly, &ierr), (interpolate != OBJ_FALSE), OBJ_FALSE,
313
+ return Integer_New(c_private_register_image(fmkr, Get_FM(fmkr, &ierr), RGB_IMAGE,
314
+ (interpolate != OBJ_FALSE), OBJ_FALSE,
297
315
  Number_to_int(w, &ierr), Number_to_int(h, &ierr), (unsigned char *)String_Ptr(data, &ierr), String_Len(data, &ierr),
298
- OBJ_NIL, OBJ_NIL, OBJ_NIL, OBJ_NIL, Number_to_int(mask_obj_num, &ierr), &ierr);
316
+ OBJ_NIL, OBJ_NIL, OBJ_NIL, OBJ_NIL, Number_to_int(mask_obj_num, &ierr),
317
+ Number_to_int(components, &ierr),
318
+ Str_Or_NULL(filters, &ierr), &ierr));
299
319
  }
300
320
 
301
- OBJ_PTR FM_private_show_cmyk_image(OBJ_PTR fmkr, OBJ_PTR llx, OBJ_PTR lly, OBJ_PTR lrx, OBJ_PTR lry,
302
- OBJ_PTR ulx, OBJ_PTR uly, OBJ_PTR interpolate, OBJ_PTR w, OBJ_PTR h, OBJ_PTR data, OBJ_PTR mask_obj_num)
321
+ OBJ_PTR FM_private_register_cmyk_image(OBJ_PTR fmkr, OBJ_PTR interpolate, OBJ_PTR w, OBJ_PTR h, OBJ_PTR data, OBJ_PTR mask_obj_num, OBJ_PTR components, OBJ_PTR filters)
303
322
  { int ierr=0;
304
- return c_private_show_image(fmkr, Get_FM(fmkr, &ierr), CMYK_IMAGE, Number_to_double(llx, &ierr), Number_to_double(lly, &ierr),
305
- Number_to_double(lrx, &ierr), Number_to_double(lry, &ierr),
306
- Number_to_double(ulx, &ierr), Number_to_double(uly, &ierr), (interpolate != OBJ_FALSE), false,
323
+ return Integer_New(c_private_register_image(fmkr, Get_FM(fmkr, &ierr), CMYK_IMAGE, (interpolate != OBJ_FALSE), false,
307
324
  Number_to_int(w, &ierr), Number_to_int(h, &ierr), (unsigned char *)String_Ptr(data, &ierr), String_Len(data, &ierr),
308
- OBJ_NIL, OBJ_NIL, OBJ_NIL, OBJ_NIL, Number_to_int(mask_obj_num, &ierr), &ierr);
325
+ OBJ_NIL, OBJ_NIL, OBJ_NIL, OBJ_NIL, Number_to_int(mask_obj_num, &ierr),
326
+ Number_to_int(components, &ierr),
327
+ Str_Or_NULL(filters, &ierr), &ierr));
309
328
  }
310
329
 
311
- OBJ_PTR FM_private_show_grayscale_image(OBJ_PTR fmkr, OBJ_PTR llx, OBJ_PTR lly, OBJ_PTR lrx, OBJ_PTR lry,
312
- OBJ_PTR ulx, OBJ_PTR uly, OBJ_PTR interpolate, OBJ_PTR w, OBJ_PTR h, OBJ_PTR data, OBJ_PTR mask_obj_num)
330
+ OBJ_PTR FM_private_register_grayscale_image(OBJ_PTR fmkr, OBJ_PTR interpolate, OBJ_PTR w, OBJ_PTR h, OBJ_PTR data, OBJ_PTR mask_obj_num, OBJ_PTR components, OBJ_PTR filters)
313
331
  { int ierr=0;
314
- return c_private_show_image(fmkr, Get_FM(fmkr, &ierr), GRAY_IMAGE, Number_to_double(llx, &ierr), Number_to_double(lly, &ierr),
315
- Number_to_double(lrx, &ierr), Number_to_double(lry, &ierr),
316
- Number_to_double(ulx, &ierr), Number_to_double(uly, &ierr), (interpolate != OBJ_FALSE), false,
332
+ return Integer_New(c_private_register_image(fmkr, Get_FM(fmkr, &ierr), GRAY_IMAGE, (interpolate != OBJ_FALSE), false,
317
333
  Number_to_int(w, &ierr), Number_to_int(h, &ierr), (unsigned char *)String_Ptr(data, &ierr), String_Len(data, &ierr),
318
- OBJ_NIL, OBJ_NIL, OBJ_NIL, OBJ_NIL, Number_to_int(mask_obj_num, &ierr), &ierr);
334
+ OBJ_NIL, OBJ_NIL, OBJ_NIL, OBJ_NIL, Number_to_int(mask_obj_num, &ierr),
335
+ Number_to_int(components, &ierr),
336
+ Str_Or_NULL(filters, &ierr), &ierr));
319
337
  }
320
338
 
321
- OBJ_PTR FM_private_show_monochrome_image(OBJ_PTR fmkr, OBJ_PTR llx, OBJ_PTR lly, OBJ_PTR lrx, OBJ_PTR lry,
322
- OBJ_PTR ulx, OBJ_PTR uly, OBJ_PTR interpolate, OBJ_PTR reversed, OBJ_PTR w, OBJ_PTR h, OBJ_PTR data, OBJ_PTR mask_obj_num)
339
+ OBJ_PTR FM_private_register_monochrome_image(OBJ_PTR fmkr, OBJ_PTR interpolate, OBJ_PTR reversed, OBJ_PTR w, OBJ_PTR h, OBJ_PTR data, OBJ_PTR mask_obj_num, OBJ_PTR filters)
323
340
  { int ierr=0;
324
- return c_private_show_image(fmkr, Get_FM(fmkr, &ierr), MONO_IMAGE, Number_to_double(llx, &ierr), Number_to_double(lly, &ierr),
325
- Number_to_double(lrx, &ierr), Number_to_double(lry, &ierr),
326
- Number_to_double(ulx, &ierr), Number_to_double(uly, &ierr), (interpolate != OBJ_FALSE), (reversed == OBJ_TRUE),
341
+ return Integer_New(c_private_register_image(fmkr, Get_FM(fmkr, &ierr), MONO_IMAGE, (interpolate != OBJ_FALSE), (reversed == OBJ_TRUE),
327
342
  Number_to_int(w, &ierr), Number_to_int(h, &ierr), (unsigned char *)String_Ptr(data, &ierr), String_Len(data, &ierr),
328
- OBJ_NIL, OBJ_NIL, OBJ_NIL, OBJ_NIL, Number_to_int(mask_obj_num, &ierr), &ierr);
343
+ OBJ_NIL, OBJ_NIL, OBJ_NIL, OBJ_NIL, Number_to_int(mask_obj_num, &ierr), 1,
344
+ Str_Or_NULL(filters, &ierr), &ierr));
329
345
  }
330
346
 
331
- OBJ_PTR FM_private_show_image(OBJ_PTR fmkr, OBJ_PTR llx, OBJ_PTR lly, OBJ_PTR lrx, OBJ_PTR lry,
332
- OBJ_PTR ulx, OBJ_PTR uly, OBJ_PTR interpolate, OBJ_PTR w, OBJ_PTR h, OBJ_PTR data,
333
- OBJ_PTR value_mask_min, OBJ_PTR value_mask_max, OBJ_PTR hival, OBJ_PTR lookup, OBJ_PTR mask_obj_num)
347
+ OBJ_PTR FM_private_register_image(OBJ_PTR fmkr,OBJ_PTR interpolate, OBJ_PTR w, OBJ_PTR h, OBJ_PTR data,
348
+ OBJ_PTR value_mask_min, OBJ_PTR value_mask_max, OBJ_PTR hival, OBJ_PTR lookup, OBJ_PTR mask_obj_num, OBJ_PTR components, OBJ_PTR filters)
334
349
  { int ierr=0;
335
- return c_private_show_image(fmkr, Get_FM(fmkr, &ierr), COLORMAP_IMAGE, Number_to_double(llx, &ierr), Number_to_double(lly, &ierr),
336
- Number_to_double(lrx, &ierr), Number_to_double(lry, &ierr),
337
- Number_to_double(ulx, &ierr), Number_to_double(uly, &ierr), (interpolate != OBJ_FALSE), false,
350
+ return Integer_New(c_private_register_image(fmkr, Get_FM(fmkr, &ierr), COLORMAP_IMAGE, (interpolate != OBJ_FALSE), false,
338
351
  Number_to_int(w, &ierr), Number_to_int(h, &ierr), (unsigned char *)String_Ptr(data, &ierr), String_Len(data, &ierr),
339
- value_mask_min, value_mask_max, hival, lookup, Number_to_int(mask_obj_num, &ierr), &ierr);
352
+ value_mask_min, value_mask_max, hival, lookup, Number_to_int(mask_obj_num, &ierr),
353
+ Number_to_int(components, &ierr),
354
+ Str_Or_NULL(filters, &ierr), &ierr));
355
+ }
356
+
357
+ OBJ_PTR FM_private_show_image_from_ref(OBJ_PTR fmkr, OBJ_PTR ref, OBJ_PTR llx, OBJ_PTR lly, OBJ_PTR lrx, OBJ_PTR lry, OBJ_PTR ulx, OBJ_PTR uly)
358
+ {
359
+ int ierr=0;
360
+ c_private_show_image_from_ref(fmkr, Get_FM(fmkr, &ierr),
361
+ Number_to_int(ref, &ierr),
362
+ Number_to_double(llx, &ierr), Number_to_double(lly, &ierr),
363
+ Number_to_double(lrx, &ierr), Number_to_double(lry, &ierr),
364
+ Number_to_double(ulx, &ierr), Number_to_double(uly, &ierr), &ierr);
365
+ RETURN_NIL;
340
366
  }
341
367
 
342
368
 
@@ -152,30 +152,34 @@ extern OBJ_PTR FM_pdf_grestore(OBJ_PTR fmkr);
152
152
 
153
153
  /*======================================================================*/
154
154
  // pdfimage.c
155
- extern OBJ_PTR FM_private_show_jpg(OBJ_PTR fmkr, OBJ_PTR filename,
156
- OBJ_PTR width, OBJ_PTR height, OBJ_PTR image_destination, OBJ_PTR mask_xo_num);
157
155
  extern OBJ_PTR FM_private_create_image_data(OBJ_PTR fmkr, OBJ_PTR data,
158
156
  OBJ_PTR first_row, OBJ_PTR last_row, OBJ_PTR first_column, OBJ_PTR last_column,
159
157
  OBJ_PTR min_OBJ_PTR, OBJ_PTR max_OBJ_PTR, OBJ_PTR max_code, OBJ_PTR if_below_range, OBJ_PTR if_above_range);
160
158
  extern OBJ_PTR FM_private_create_monochrome_image_data(OBJ_PTR fmkr, OBJ_PTR data,
161
159
  OBJ_PTR first_row, OBJ_PTR last_row, OBJ_PTR first_column, OBJ_PTR last_column,
162
160
  OBJ_PTR boundary, OBJ_PTR reverse);
163
- extern OBJ_PTR FM_private_show_image(OBJ_PTR fmkr, OBJ_PTR llx, OBJ_PTR lly, OBJ_PTR lrx, OBJ_PTR lry, OBJ_PTR ulx, OBJ_PTR uly,
164
- OBJ_PTR interpolate, OBJ_PTR w, OBJ_PTR h, OBJ_PTR data, OBJ_PTR OBJ_PTR_mask_min, OBJ_PTR OBJ_PTR_mask_max,
165
- OBJ_PTR hival, OBJ_PTR lookup, OBJ_PTR mask_xo_num);
166
- extern OBJ_PTR FM_private_show_hls_image(OBJ_PTR fmkr,
167
- OBJ_PTR llx, OBJ_PTR lly, OBJ_PTR lrx, OBJ_PTR lry, OBJ_PTR ulx, OBJ_PTR uly,
168
- OBJ_PTR interpolate, OBJ_PTR w, OBJ_PTR h, OBJ_PTR data, OBJ_PTR mask_xo_num);
169
- extern OBJ_PTR FM_private_show_rgb_image(OBJ_PTR fmkr,
170
- OBJ_PTR llx, OBJ_PTR lly, OBJ_PTR lrx, OBJ_PTR lry, OBJ_PTR ulx, OBJ_PTR uly,
171
- OBJ_PTR interpolate, OBJ_PTR w, OBJ_PTR h, OBJ_PTR data, OBJ_PTR mask_xo_num);
172
- extern OBJ_PTR FM_private_show_cmyk_image(OBJ_PTR fmkr,
173
- OBJ_PTR llx, OBJ_PTR lly, OBJ_PTR lrx, OBJ_PTR lry, OBJ_PTR ulx, OBJ_PTR uly,
174
- OBJ_PTR interpolate, OBJ_PTR w, OBJ_PTR h, OBJ_PTR data, OBJ_PTR mask_xo_num);
175
- extern OBJ_PTR FM_private_show_grayscale_image(OBJ_PTR fmkr,
176
- OBJ_PTR llx, OBJ_PTR lly, OBJ_PTR lrx, OBJ_PTR lry, OBJ_PTR ulx, OBJ_PTR uly,
177
- OBJ_PTR interpolate, OBJ_PTR w, OBJ_PTR h, OBJ_PTR data, OBJ_PTR mask_xo_num);
178
- extern OBJ_PTR FM_private_show_monochrome_image(OBJ_PTR fmkr, OBJ_PTR llx, OBJ_PTR lly, OBJ_PTR lrx, OBJ_PTR lry, OBJ_PTR ulx, OBJ_PTR uly,
161
+
162
+ extern OBJ_PTR FM_private_show_image_from_ref(OBJ_PTR fmkr, OBJ_PTR ref, OBJ_PTR llx, OBJ_PTR lly, OBJ_PTR lrx, OBJ_PTR lry, OBJ_PTR ulx, OBJ_PTR uly);
163
+
164
+ extern OBJ_PTR FM_private_register_jpg(OBJ_PTR fmkr, OBJ_PTR filename,
165
+ OBJ_PTR width, OBJ_PTR height,
166
+ OBJ_PTR mask_xo_num);
167
+
168
+ extern OBJ_PTR FM_jpg_info(OBJ_PTR fmkr, OBJ_PTR filename);
169
+
170
+ extern OBJ_PTR FM_private_register_image(OBJ_PTR fmkr,
171
+ OBJ_PTR interpolate, OBJ_PTR w, OBJ_PTR h, OBJ_PTR data, OBJ_PTR OBJ_PTR_mask_min, OBJ_PTR OBJ_PTR_mask_max,
172
+ OBJ_PTR hival, OBJ_PTR lookup, OBJ_PTR mask_xo_num, OBJ_PTR components);
173
+
174
+ extern OBJ_PTR FM_private_register_hls_image(OBJ_PTR fmkr,
175
+ OBJ_PTR interpolate, OBJ_PTR w, OBJ_PTR h, OBJ_PTR data, OBJ_PTR mask_xo_num, OBJ_PTR components);
176
+ extern OBJ_PTR FM_private_register_rgb_image(OBJ_PTR fmkr,
177
+ OBJ_PTR interpolate, OBJ_PTR w, OBJ_PTR h, OBJ_PTR data, OBJ_PTR mask_xo_num, OBJ_PTR components);
178
+ extern OBJ_PTR FM_private_register_cmyk_image(OBJ_PTR fmkr,
179
+ OBJ_PTR interpolate, OBJ_PTR w, OBJ_PTR h, OBJ_PTR data, OBJ_PTR mask_xo_num, OBJ_PTR components);
180
+ extern OBJ_PTR FM_private_register_grayscale_image(OBJ_PTR fmkr,
181
+ OBJ_PTR interpolate, OBJ_PTR w, OBJ_PTR h, OBJ_PTR data, OBJ_PTR mask_xo_num, OBJ_PTR components);
182
+ extern OBJ_PTR FM_private_register_monochrome_image(OBJ_PTR fmkr,
179
183
  OBJ_PTR interpolate, OBJ_PTR reversed, OBJ_PTR w, OBJ_PTR h, OBJ_PTR data, OBJ_PTR mask_xo_num);
180
184
 
181
185
  /*======================================================================*/
@@ -86,6 +86,8 @@ module Dobjects
86
86
  'default' => 0.0/0.0, # defaults to NaN
87
87
  'initial_size' => 5001,
88
88
  'remove_space' => true ,# removes spaces at the beginning of the lines
89
+ 'last_col' => -1, # Read all columns
90
+ 'text_columns' => [], # Not a single column is text
89
91
  }
90
92
 
91
93
  # This function is a wrapper for #fast_fancy_read that reflects the
@@ -23,6 +23,9 @@
23
23
  require 'Tioga/FigureConstants.rb'
24
24
  require 'Tioga/Utils'
25
25
 
26
+ require "tmpdir"
27
+ require "fileutils"
28
+
26
29
  module Tioga
27
30
  class FigureMaker
28
31
 
@@ -38,7 +41,7 @@ class FigureMaker
38
41
 
39
42
  # This URL will contain tioga-(...) when it is exported from the
40
43
  # SVN repository. This is where we'll look for version information.
41
- SVN_URL = '$HeadURL: svn+ssh://rubyforge.org/var/svn/tioga/tags/tioga/Tioga%201.17/lib/Tioga/FigMkr.rb $'
44
+ SVN_URL = '$HeadURL: svn+ssh://rubyforge.org/var/svn/tioga/tags/tioga/Tioga%201.18/lib/Tioga/FigMkr.rb $'
42
45
 
43
46
  TIOGA_VERSION = if SVN_URL =~ /tags\/tioga\/Tioga%20([^\/]+)/
44
47
  $1
@@ -165,6 +168,11 @@ class FigureMaker
165
168
  attr_accessor :measures_info
166
169
 
167
170
 
171
+ # Maximum number of pdflatex calls. If nil, then unlimited, but
172
+ # that could be a very bad idea.
173
+ attr_accessor :max_nested_pdflatex_calls
174
+ attr_reader :current_pdflatex_call
175
+
168
176
 
169
177
  # If we want to use #legend_bounding_box. It is off by default
170
178
  # as it causes a systematic second run of pdflatex.
@@ -317,6 +325,9 @@ class FigureMaker
317
325
  # We don't measure legends by default.
318
326
  @measure_legends = false
319
327
 
328
+ # Max number of pdflatex runs
329
+ @max_nested_pdflatex_calls = 3
330
+
320
331
  # By default, we use Bill's algorithm for major ticks positions
321
332
  self.vincent_or_bill = false
322
333
  self.log_minor_ticks_limit = 10
@@ -1651,13 +1662,97 @@ class FigureMaker
1651
1662
 
1652
1663
 
1653
1664
  @@keys_for_show_image = FigureMaker.make_name_lookup_hash([
1654
- 'll', 'lr', 'ul', 'w', 'width', 'height', 'h',
1655
- 'opacity_mask', 'stencil_mask',
1665
+ 'll', 'lr', 'ul', 'w', 'width', 'height', 'h', 'ref',
1666
+ 'opacity_mask', 'stencil_mask', 'bits', 'pdf_filters',
1656
1667
  'jpg', 'JPG', 'jpeg', 'JPEG', 'interpolate', 'data', 'value_mask',
1657
1668
  'color_space', 'color_map', 'colormap'])
1658
1669
  def show_image(dict)
1659
1670
  internal_show_image(dict, false)
1660
1671
  end
1672
+
1673
+ # Only register an image
1674
+ def register_image(dict)
1675
+ internal_show_image(dict, true)
1676
+ end
1677
+
1678
+ def load_png(file)
1679
+ if File.readable?(file)
1680
+ Dir::mktmpdir do |dir|
1681
+ FileUtils::cp(file, "#{dir}/image.png")
1682
+ Dir::chdir(dir) do
1683
+ open("read.tex", "w") do |f|
1684
+ f.puts <<'EOD'
1685
+ \documentclass{article}
1686
+ \usepackage{graphicx}
1687
+ \pdfcompresslevel=0
1688
+ \pdfobjcompresslevel=0
1689
+ \begin{document}
1690
+ \includegraphics[width=1cm]{image}
1691
+ \end{document}
1692
+ EOD
1693
+ end
1694
+ pdflatex = "pdflatex"
1695
+ syscmd = "#{pdflatex} -interaction nonstopmode read.tex"
1696
+ IO::popen(syscmd, "r+") do |f|
1697
+ f.close_write
1698
+ for line in f
1699
+ # Shall we do something with those ?
1700
+ end
1701
+ end
1702
+
1703
+ # Now, we open the PDF file and have fun with it.
1704
+ open("read.pdf", 'rb') do |f|
1705
+
1706
+ ret = nil
1707
+ cur = nil
1708
+ len = nil
1709
+ while l = f.gets("\n")
1710
+ if ! ret && l =~ /\/Subtype\s*\/Image\s*/
1711
+ ret = {}
1712
+ cur = ret
1713
+ elsif cur && l=~ /\/Width\s*(\d+)\s*/
1714
+ cur['width'] = $1.to_i
1715
+ elsif cur && l=~ /\/Height\s*(\d+)\s*/
1716
+ cur['height'] = $1.to_i
1717
+ elsif cur && l =~ /\/Length\s*(\d+)\s*/
1718
+ len = $1.to_i
1719
+ elsif cur && l =~ /\/(Filter|DecodePar)/ && (!cur['data'])
1720
+ cur['pdf_filters'] ||= ''
1721
+ cur['pdf_filters'] << l
1722
+ elsif cur && l =~ /^\s*\/BitsPerComponent\s*(\d+)\s*/
1723
+ cur['bits'] = $1.to_i
1724
+ elsif cur && l =~ /\/ColorSpace\s*(\S+)\s*/
1725
+ cs = $1
1726
+ if cs == "/DeviceGray"
1727
+ cs = 'gray'
1728
+ elsif cs == "/DeviceRGB"
1729
+ cs = "rgb"
1730
+ else
1731
+ raise "Unsupported colorspace for file #{file}: '#{cs}'"
1732
+ end
1733
+ cur['color_space'] = cs
1734
+ elsif cur && l =~ /\/SMask\s*(\d+)\s*/
1735
+ cur['opacity_mask'] = {}
1736
+ elsif cur && len && l =~ /stream/
1737
+ cur['data'] = f.read(len)
1738
+ if cur['opacity_mask']
1739
+ cur = cur['opacity_mask']
1740
+ len = nil
1741
+ else
1742
+ return ret
1743
+ end
1744
+ end
1745
+ end
1746
+ return ret
1747
+ end
1748
+
1749
+ end
1750
+ end
1751
+ else
1752
+ raise "File #{file} not readable"
1753
+ end
1754
+ end
1755
+
1661
1756
 
1662
1757
  @@keys_for_create_colormap = FigureMaker.make_name_lookup_hash(['length', 'points', 'Rs', 'Gs', 'Bs', 'Hs', 'Ls', 'Ss'])
1663
1758
  def create_colormap(dict)
@@ -1944,19 +2039,20 @@ class FigureMaker
1944
2039
  elsif loc == BOTTOM
1945
2040
  shift = self.text_shift_on_bottom if shift == nil
1946
2041
  else
2042
+ angle_add = 0
1947
2043
  if (loc == AT_X_ORIGIN)
1948
2044
  shift = self.text_shift_from_x_origin if shift == nil
1949
- xloc = shift*self.char_height_dx
2045
+ xloc = shift*self.default_text_height_dx
1950
2046
  yloc = convert_frame_to_figure_y(position)
1951
- return
2047
+ angle_add = 90
1952
2048
  elsif (loc == AT_Y_ORIGIN)
1953
2049
  shift = self.text_shift_from_y_origin if shift == nil
1954
- yloc = shift*self.char_height_dy
2050
+ yloc = shift*self.default_text_height_dx
1955
2051
  xloc = convert_frame_to_figure_x(position)
1956
2052
  else
1957
2053
  raise "Sorry: 'loc' must be LEFT, RIGHT, TOP, BOTTOM, AT_X_ORIGIN, or AT_Y_ORIGIN for show_text"
1958
2054
  end
1959
- show_rotated_label(text, xloc, yloc, scale, angle, just, align,
2055
+ show_rotated_label(text, xloc, yloc, scale, angle + angle_add, just, align,
1960
2056
  dict['measure'])
1961
2057
  return
1962
2058
  end
@@ -2148,17 +2244,25 @@ class FigureMaker
2148
2244
  num = get_num_for_pdf(num)
2149
2245
  result = start_making_pdf(num)
2150
2246
  return unless result
2247
+
2248
+ @current_pdflatex_call ||= 0
2151
2249
  begin
2152
2250
  @figure_pdfs[num] = finish_making_pdf(@figure_names[num])
2153
2251
  # If the keys have changed, we run that again.
2154
2252
  rescue Exception => e
2155
2253
  p e, e.backtrace
2156
2254
  end
2157
-
2255
+
2158
2256
  if @measures.keys != old_measure_keys
2159
- # we dont need to pass &cmd since it has now been defined
2160
- make_pdf(num)
2257
+ @current_pdflatex_call += 1
2258
+
2259
+ # We limit
2260
+ if (!@max_nested_pdflatex_calls || (@current_pdflatex_call < @max_nested_pdflatex_calls))
2261
+ # we dont need to pass &cmd since it has now been defined
2262
+ make_pdf(num)
2263
+ end
2161
2264
  end
2265
+ @current_pdflatex_call = nil
2162
2266
  return @figure_pdfs[num]
2163
2267
  end
2164
2268
 
@@ -2390,6 +2494,12 @@ EOE
2390
2494
  # p @fm_data
2391
2495
  private_save_measure(key, *val)
2392
2496
  end
2497
+
2498
+ # Delete all keys in @
2499
+ extra = @measures_info.keys - @measures.keys
2500
+ for e in extra
2501
+ @measures_info.delete(e)
2502
+ end
2393
2503
 
2394
2504
  result = $?
2395
2505
  if !result
@@ -2441,74 +2551,71 @@ EOE
2441
2551
  return false
2442
2552
  end
2443
2553
 
2444
- def internal_show_image(dict, is_mask)
2445
- check_dict(dict, @@keys_for_show_image, 'show_image')
2446
- ll = dict['ll']; lr = dict['lr']; ul = dict['ul']
2447
- w = alt_names(dict, 'w', 'width')
2448
- h = alt_names(dict, 'h', 'height')
2449
- opacity_mask = alt_names(dict, 'opacity_mask', 'stencil_mask')
2450
- if opacity_mask != nil
2451
- mask_xo_num = internal_show_image(opacity_mask, true)
2452
- else
2453
- mask_xo_num = 0
2454
- end
2455
- filename = alt_names(dict, 'jpg', 'JPG')
2456
- filename = dict['jpeg'] if filename == nil
2457
- filename = dict['JPEG'] if filename == nil
2458
- if filename != nil
2459
- return private_show_jpg(filename, w, h, [ll[0], ll[1], lr[0], lr[1], ul[0], ul[1]], mask_xo_num)
2460
- end
2554
+ def internal_show_image(dict, register_only)
2555
+ check_dict(dict, @@keys_for_show_image, 'show_image')
2556
+ ll = dict['ll']; lr = dict['lr']; ul = dict['ul']
2557
+ w = alt_names(dict, 'w', 'width')
2558
+ h = alt_names(dict, 'h', 'height')
2559
+ opacity_mask = alt_names(dict, 'opacity_mask', 'stencil_mask')
2560
+ bits = dict['bits'] || 8
2561
+ filters = dict['pdf_filters'] || nil
2562
+ ref = dict['ref'] || nil
2563
+ if opacity_mask != nil
2564
+ om = opacity_mask.dup
2565
+ mask_xo_num = om['ref'] || internal_show_image(om, true)
2566
+ else
2567
+ mask_xo_num = 0
2568
+ end
2569
+ filename = alt_names(dict, 'jpg', 'JPG')
2570
+ filename = dict['jpeg'] if filename == nil
2571
+ filename = dict['JPEG'] if filename == nil
2572
+ if ref
2573
+ # Nothing to register, just reuse the image
2574
+ elsif filename != nil
2575
+ ref = private_register_jpg(filename, w, h, mask_xo_num)
2576
+ else
2461
2577
  interpolate = get_if_given_else_default(dict, 'interpolate', true)
2462
2578
  data = dict['data']
2463
2579
  value_mask = dict['value_mask']
2464
2580
  color_space = alt_names(dict, 'color_space', 'colormap')
2465
2581
  color_space = dict['color_map'] if color_space == nil
2466
- if color_space == nil
2467
- raise "Sorry: must specify 'color_space' for the image"
2468
- end
2469
- if color_space == 'MONO' || color_space == 'mono'
2470
- raise "Sorry: monochrome image must not itself have a mask" unless mask_xo_num == 0
2471
- reversed = get_if_given_else_default(dict, 'reversed', false)
2472
- xo_obj = private_show_monochrome_image(ll[0], ll[1], lr[0], lr[1], ul[0], ul[1],
2473
- interpolate, reversed, w, h, data, ((is_mask)? -1 : 0))
2474
- return is_mask ? xo_obj : self
2475
- end
2476
- if color_space == 'GRAY' || color_space == 'gray' || color_space == 'GREY' || color_space == 'grey'
2477
- if is_mask
2478
- raise("Sorry: mask must not itself have a mask") unless mask_xo_num == 0
2479
- mask_xo_num = -1
2480
- end
2481
- xo_obj = private_show_grayscale_image(ll[0], ll[1], lr[0], lr[1], ul[0], ul[1],
2482
- interpolate, w, h, data, mask_xo_num)
2483
- return is_mask ? xo_obj : self
2484
- end
2485
- if is_mask
2486
- raise "Sorry: mask image must have 'color_space' set to 'gray' or 'mono'"
2487
- end
2488
- if color_space == 'RGB' || color_space == 'rgb'
2489
- private_show_rgb_image(ll[0], ll[1], lr[0], lr[1], ul[0], ul[1], interpolate, w, h, data, mask_xo_num)
2490
- return self
2491
- end
2492
- if color_space == 'HLS' || color_space == 'hls'
2493
- private_show_hls_image(ll[0], ll[1], lr[0], lr[1], ul[0], ul[1], interpolate, w, h, data, mask_xo_num)
2494
- return self
2495
- end
2496
- if color_space == 'CMYK' || color_space == 'cmyk'
2497
- private_show_cmyk_image(ll[0], ll[1], lr[0], lr[1], ul[0], ul[1], interpolate, w, h, data, mask_xo_num)
2498
- return self
2499
- end
2500
- if value_mask == nil
2582
+ case color_space
2583
+ when nil
2584
+ raise "Sorry: must specify 'color_space' for the image"
2585
+ when 'MONO', 'mono'
2586
+ raise "Sorry: monochrome image must not itself have a mask" unless mask_xo_num == 0
2587
+ reversed = get_if_given_else_default(dict, 'reversed', false)
2588
+ ref = private_register_monochrome_image(interpolate, reversed, w, h, data, ((register_only)? -1 : 0), filters)
2589
+ when 'GRAY', 'gray', 'GREY', 'grey'
2590
+ if register_only
2591
+ raise("Sorry: mask must not itself have a mask") unless mask_xo_num == 0
2592
+ mask_xo_num = -1
2593
+ end
2594
+ ref = private_register_grayscale_image(interpolate, w, h, data, mask_xo_num, bits, filters)
2595
+ when 'RGB', 'rgb'
2596
+ ref = private_register_rgb_image(interpolate, w, h, data, mask_xo_num, bits, filters)
2597
+ when 'HLS', 'hls'
2598
+ ref = private_register_hls_image(interpolate, w, h, data, mask_xo_num, bits, filters)
2599
+ when 'CMYK', 'cmyk'
2600
+ ref = private_register_cmyk_image(interpolate, w, h, data, mask_xo_num, bits, filters)
2601
+ else
2602
+ if value_mask == nil
2501
2603
  value_mask_min = value_mask_max = 256
2502
- elsif value_mask.kind_of?Integer
2604
+ elsif value_mask.kind_of?Integer
2503
2605
  value_mask_min = value_mask_max = value_mask
2504
- else
2606
+ else
2505
2607
  value_mask_min = value_mask[0];
2506
2608
  value_mask_max = value_mask[1];
2609
+ end
2610
+ ref = private_register_image(interpolate,
2611
+ w, h, data, value_mask_min, value_mask_max, color_space[0], color_space[1], mask_xo_num, bits, filters)
2507
2612
  end
2508
- private_show_image(
2509
- ll[0], ll[1], lr[0], lr[1], ul[0], ul[1], interpolate,
2510
- w, h, data, value_mask_min, value_mask_max, color_space[0], color_space[1], mask_xo_num)
2511
- return self
2613
+ end
2614
+ if ! register_only
2615
+ private_show_image_from_ref(ref,
2616
+ ll[0], ll[1], lr[0], lr[1], ul[0], ul[1])
2617
+ end
2618
+ return ref
2512
2619
  end
2513
2620
 
2514
2621
  def report_error(er, msg)