split/Tioga/figures.c in tioga-1.6 vs split/Tioga/figures.c in tioga-1.7
- old
+ new
@@ -23,57 +23,61 @@
:stopdoc:
*/
#include "figures.h"
#include "pdfs.h"
+#include "wrappers.h"
+#include "dvector.h"
+#include "dtable.h"
#include "flate.h"
#include <symbols.h>
#include "../symbols.c"
#include <stdio.h>
-char *data_dir = NULL;
-VALUE cFM; /* the Tioga/FigureMaker class object */
+#define DBL_ATTR(attr) \
+static VALUE FM_##attr##_get(VALUE fmkr) { int ierr=0; FM *p = Get_FM(fmkr,&ierr); return (ierr != 0)? OBJ_NIL : rb_float_new(p->attr); } \
+static VALUE FM_##attr##_set(VALUE fmkr, VALUE val) { \
+ int ierr=0; FM *p = Get_FM(fmkr,&ierr); if (ierr != 0) RETURN_NIL; VALUE v = rb_Float(val); p->attr = NUM2DBL(v); return val; }
-static void FM_mark(FM *p) { /* all of the VALUEs in the FM struct should be marked */
- rb_gc_mark(p->stroke_color);
- rb_gc_mark(p->fill_color);
- rb_gc_mark(p->line_type);
- rb_gc_mark(p->title);
- rb_gc_mark(p->title_color);
- rb_gc_mark(p->xlabel);
- rb_gc_mark(p->xlabel_color);
- rb_gc_mark(p->ylabel);
- rb_gc_mark(p->ylabel_color);
- rb_gc_mark(p->xaxis_stroke_color);
- rb_gc_mark(p->xaxis_locations_for_major_ticks);
- rb_gc_mark(p->xaxis_locations_for_minor_ticks);
- rb_gc_mark(p->yaxis_stroke_color);
- rb_gc_mark(p->yaxis_locations_for_major_ticks);
- rb_gc_mark(p->yaxis_locations_for_minor_ticks);
- rb_gc_mark(p->fm);
-}
+#define INT_ATTR(attr) \
+static VALUE FM_##attr##_get(VALUE fmkr) { int ierr=0; FM *p = Get_FM(fmkr,&ierr); return (ierr != 0)? OBJ_NIL : INT2FIX(p->attr); } \
+static VALUE FM_##attr##_set(VALUE fmkr, VALUE val) { \
+ int ierr=0; FM *p = Get_FM(fmkr,&ierr); if (ierr != 0) RETURN_NIL; VALUE v = rb_Integer(val); p->attr = NUM2INT(v); return val; }
-static void FM_free(FM *p) {
- free(p);
-}
+#define VAL_ATTR(attr) \
+static VALUE FM_##attr##_get(VALUE fmkr) { int ierr=0; FM *p = Get_FM(fmkr,&ierr); return (ierr != 0)? OBJ_NIL : p->attr; } \
+static VALUE FM_##attr##_set(VALUE fmkr, VALUE val) { \
+ int ierr=0; FM *p = Get_FM(fmkr,&ierr); if (ierr != 0) RETURN_NIL; p->attr = val; return val; }
-static VALUE FM_alloc(VALUE klass) {
- FM *p;
- VALUE ary = Data_Make_Struct(klass, FM, FM_mark, FM_free, p);
- Initialize_Figure(ary);
- p->fm = ary;
- return ary;
-}
+#define BOOL_ATTR(attr) \
+static VALUE FM_##attr##_get(VALUE fmkr) { int ierr=0; FM *p = Get_FM(fmkr,&ierr); return (ierr != 0)? OBJ_NIL : ((p->attr)? Qtrue : Qfalse); } \
+static VALUE FM_##attr##_set(VALUE fmkr, VALUE val) { \
+ int ierr=0; FM *p = Get_FM(fmkr,&ierr); if (ierr != 0) RETURN_NIL; p->attr = (val != Qfalse); return val; }
-bool Is_FM(VALUE fmkr) { return ( TYPE(fmkr) == T_DATA && RDATA(fmkr)->dfree == (RUBY_DATA_FUNC)FM_free ); }
+#define RO_DBL_ATTR(attr) \
+static VALUE FM_##attr##_get(VALUE fmkr) { int ierr=0; FM *p = Get_FM(fmkr,&ierr); return (ierr != 0)? OBJ_NIL : rb_float_new(p->attr); }
-FM *Get_FM(VALUE fmkr) {
- FM *p;
- Data_Get_Struct(fmkr, FM, p);
+#define RO_INT_ATTR(attr) \
+static VALUE FM_##attr##_get(VALUE fmkr) { int ierr=0; FM *p = Get_FM(fmkr,&ierr); return (ierr != 0)? OBJ_NIL : INT2FIX(p->attr); }
+
+#define RO_VAL_ATTR(attr) \
+static VALUE FM_##attr##_get(VALUE fmkr) { int ierr=0; FM *p = Get_FM(fmkr,&ierr); return (ierr != 0)? OBJ_NIL : p->attr; }
+
+#define RO_BOOL_ATTR(attr) \
+static VALUE FM_##attr##_get(VALUE fmkr) { int ierr=0; FM *p = Get_FM(fmkr,&ierr); return (ierr != 0)? OBJ_NIL : ((p->attr)? Qtrue : Qfalse); }
+
+
+char *data_dir = NULL;
+
+OBJ_PTR cFM; /* the Tioga/FigureMaker class object */
+
+FM *Get_FM(OBJ_PTR fmkr, int *ierr) {
+ FM *p = (FM *)Dvector_Data_for_Write(Get_fm_data_attr(fmkr, ierr), NULL);
+ if (*ierr != 0) RAISE_ERROR("FigMkr is missing @fm_data", ierr);
return p;
}
/* page attribute accessors */
RO_BOOL_ATTR(root_figure)
@@ -127,77 +131,65 @@
DBL_ATTR(text_shift_from_x_origin)
DBL_ATTR(text_shift_from_y_origin)
/* graphics attribute accessors */
RO_DBL_ATTR(default_line_scale)
- RO_VAL_ATTR(stroke_color)
- RO_VAL_ATTR(fill_color)
RO_DBL_ATTR(line_width)
RO_INT_ATTR(line_cap)
RO_INT_ATTR(line_join)
RO_DBL_ATTR(miter_limit)
RO_DBL_ATTR(stroke_opacity)
RO_DBL_ATTR(fill_opacity)
- RO_VAL_ATTR(line_type)
/* Title */
RO_BOOL_ATTR(title_visible)
- VAL_ATTR(title)
INT_ATTR(title_side)
DBL_ATTR(title_position)
DBL_ATTR(title_scale)
DBL_ATTR(title_shift)
DBL_ATTR(title_angle)
INT_ATTR(title_alignment)
INT_ATTR(title_justification)
- VAL_ATTR(title_color)
+ //VAL_ATTR(title_color)
/* X label */
RO_BOOL_ATTR(xlabel_visible)
- VAL_ATTR(xlabel)
DBL_ATTR(xlabel_position)
DBL_ATTR(xlabel_scale)
DBL_ATTR(xlabel_shift)
DBL_ATTR(xlabel_angle)
INT_ATTR(xlabel_side)
INT_ATTR(xlabel_alignment)
INT_ATTR(xlabel_justification)
- VAL_ATTR(xlabel_color)
/* Y label */
RO_BOOL_ATTR(ylabel_visible)
- VAL_ATTR(ylabel)
DBL_ATTR(ylabel_position)
DBL_ATTR(ylabel_scale)
DBL_ATTR(ylabel_shift)
DBL_ATTR(ylabel_angle)
INT_ATTR(ylabel_side)
INT_ATTR(ylabel_alignment)
INT_ATTR(ylabel_justification)
- VAL_ATTR(ylabel_color)
/* X axis */
RO_BOOL_ATTR(xaxis_visible)
INT_ATTR(xaxis_loc)
INT_ATTR(xaxis_type)
DBL_ATTR(xaxis_line_width)
- VAL_ATTR(xaxis_stroke_color)
DBL_ATTR(xaxis_major_tick_width)
DBL_ATTR(xaxis_minor_tick_width)
DBL_ATTR(xaxis_major_tick_length)
DBL_ATTR(xaxis_minor_tick_length)
BOOL_ATTR(xaxis_log_values)
BOOL_ATTR(xaxis_ticks_inside)
BOOL_ATTR(xaxis_ticks_outside)
DBL_ATTR(xaxis_tick_interval)
DBL_ATTR(xaxis_min_between_major_ticks)
INT_ATTR(xaxis_number_of_minor_intervals)
- VAL_ATTR(xaxis_locations_for_major_ticks)
- VAL_ATTR(xaxis_locations_for_minor_ticks)
BOOL_ATTR(xaxis_use_fixed_pt)
INT_ATTR(xaxis_digits_max)
- VAL_ATTR(xaxis_tick_labels)
INT_ATTR(xaxis_numeric_label_decimal_digits)
DBL_ATTR(xaxis_numeric_label_scale)
DBL_ATTR(xaxis_numeric_label_shift)
DBL_ATTR(xaxis_numeric_label_angle)
INT_ATTR(xaxis_numeric_label_alignment)
@@ -212,26 +204,22 @@
/* Y axis */
RO_BOOL_ATTR(yaxis_visible)
INT_ATTR(yaxis_loc)
INT_ATTR(yaxis_type)
DBL_ATTR(yaxis_line_width)
- VAL_ATTR(yaxis_stroke_color)
DBL_ATTR(yaxis_major_tick_width)
DBL_ATTR(yaxis_minor_tick_width)
DBL_ATTR(yaxis_major_tick_length)
DBL_ATTR(yaxis_minor_tick_length)
BOOL_ATTR(yaxis_log_values)
BOOL_ATTR(yaxis_ticks_inside)
BOOL_ATTR(yaxis_ticks_outside)
DBL_ATTR(yaxis_tick_interval)
DBL_ATTR(yaxis_min_between_major_ticks)
INT_ATTR(yaxis_number_of_minor_intervals)
- VAL_ATTR(yaxis_locations_for_major_ticks)
- VAL_ATTR(yaxis_locations_for_minor_ticks)
BOOL_ATTR(yaxis_use_fixed_pt)
INT_ATTR(yaxis_digits_max)
- VAL_ATTR(yaxis_tick_labels)
INT_ATTR(yaxis_numeric_label_decimal_digits)
DBL_ATTR(yaxis_numeric_label_scale)
DBL_ATTR(yaxis_numeric_label_shift)
DBL_ATTR(yaxis_numeric_label_angle)
INT_ATTR(yaxis_numeric_label_alignment)
@@ -260,16 +248,30 @@
INT_ATTR(debug_verbosity_level)
/* Warning on non-ok numbers */
BOOL_ATTR(croak_on_nonok_numbers)
+bool Get_initialized() {
+ OBJ_PTR v = rb_cv_get(cFM, "@@initialized");
+ return v != OBJ_FALSE && v != OBJ_NIL;
+}
+
+void Set_initialized() {
+ rb_cv_set(cFM, "@@initialized", OBJ_TRUE);
+}
+
+static void Set_fm_data_size() {
+ rb_cv_set(cFM, "@@fm_data_size", Integer_New(1 + (sizeof(FM) / sizeof(double))));
+ // size is number of doubles needed to hold FM data
+}
+
#define attr_reader(attr) rb_define_method(cFM, #attr , FM_##attr##_get, 0);
#define attr_writer(attr) rb_define_method(cFM, #attr "=", FM_##attr##_set, 1);
#define attr_accessors(attr) attr_reader(attr) attr_writer(attr)
void Init_FigureMaker(void) {
- /* called by Ruby when the extension is loaded */
+ /* called by Ruby when the extension is loaded */
/* this function has been modified by Vincent Fourmond for the splitting
out of libraries more general than Tioga */
/*
@@ -284,16 +286,16 @@
rb_require("Dobjects/Dvector");
rb_require("Dobjects/Dtable");
rb_require("Flate");
- VALUE mTioga = rb_define_module("Tioga");
+ OBJ_PTR mTioga = rb_define_module("Tioga");
/* and now, we need to import Dobjects and Flate modules*/
- VALUE mDobjects = rb_define_module("Dobjects");
- VALUE mFlate = rb_define_module("Flate");
+ OBJ_PTR mDobjects = rb_define_module("Dobjects");
+ OBJ_PTR mFlate = rb_define_module("Flate");
rb_include_module(mTioga, mDobjects);
rb_include_module(mTioga, mFlate);
cFM = rb_define_class_under(mTioga, "FigureMaker", rb_cObject);
@@ -302,17 +304,17 @@
/* Inclusion of the external objects to get them easily */
rb_include_module(cFM, mDobjects);
rb_include_module(cFM, mFlate);
- rb_define_alloc_func(cFM, FM_alloc);
Init_IDs();
Init_Font_Dictionary();
rb_define_method(cFM, "private_make", FM_private_make, 2);
rb_define_method(cFM, "get_save_filename", FM_get_save_filename, 1);
rb_define_method(cFM, "private_make_portfolio", FM_private_make_portfolio, 3);
-
+ rb_define_method(cFM, "private_init_fm_data", FM_private_init_fm_data, 0);
+
/* page attribute accessors */
attr_reader(root_figure)
attr_reader(in_subplot)
attr_reader(page_left)
attr_reader(page_right)
@@ -362,19 +364,20 @@
attr_accessors(stroke_color)
attr_accessors(fill_color)
attr_accessors(line_width)
attr_accessors(line_cap)
attr_accessors(line_join)
+ rb_define_method(cFM, "line_type_set", FM_line_type_set, 1);
attr_accessors(miter_limit)
attr_accessors(stroke_opacity)
attr_accessors(fill_opacity)
- attr_accessors(line_type)
/* croak on non ok */
attr_accessors(croak_on_nonok_numbers)
/* methods */
- rb_define_method(cFM, "private_context", FM_private_context, 1);
+ rb_define_method(cFM, "pdf_gsave", FM_pdf_gsave, 0);
+ rb_define_method(cFM, "pdf_grestore", FM_pdf_grestore, 0);
rb_define_method(cFM, "private_set_bounds", FM_private_set_bounds, 4);
rb_define_method(cFM, "private_set_subframe", FM_private_set_subframe, 4);
rb_define_method(cFM, "doing_subfigure", FM_doing_subfigure, 0);
/* colors */
rb_define_method(cFM, "hls_to_rgb", FM_hls_to_rgb, 1);
@@ -413,21 +416,24 @@
rb_define_method(cFM, "convert_figure_to_output_dx", FM_convert_figure_to_output_dx, 1);
rb_define_method(cFM, "convert_figure_to_output_dy", FM_convert_figure_to_output_dy, 1);
rb_define_method(cFM, "convert_output_to_figure_x", FM_convert_output_to_figure_x, 1);
rb_define_method(cFM, "convert_output_to_figure_y", FM_convert_output_to_figure_y, 1);
rb_define_method(cFM, "convert_output_to_figure_dx", FM_convert_output_to_figure_dx, 1);
- rb_define_method(cFM, "convert_output_to_figuret_dy", FM_convert_output_to_figure_dy, 1);
+ rb_define_method(cFM, "convert_output_to_figure_dy", FM_convert_output_to_figure_dy, 1);
rb_define_method(cFM, "convert_to_degrees", FM_convert_to_degrees, 2);
/* text */
rb_define_method(cFM, "private_set_default_font_size", FM_private_set_default_font_size, 1);
rb_define_method(cFM, "rescale_text", FM_rescale_text, 1);
- rb_define_method(cFM, "show_rotated_text", FM_show_rotated_text, 8);
- rb_define_method(cFM, "show_rotated_label", FM_show_rotated_label, 7);
+ rb_define_method(cFM, "show_rotated_text", FM_show_rotated_text, 9);
+ rb_define_method(cFM, "show_rotated_label", FM_show_rotated_label, 8);
rb_define_method(cFM, "check_label_clip", FM_check_label_clip, 2);
+/* text measurements */
+ rb_define_method(cFM, "private_save_measure", FM_save_measure, 4);
/* path construction */
rb_define_method(cFM, "move_to_point", FM_move_to_point, 2);
rb_define_method(cFM, "append_point_to_path", FM_append_point_to_path, 2);
+ rb_define_method(cFM, "bezier_control_points", FM_bezier_control_points, 6);
rb_define_method(cFM, "append_curve_to_path", FM_append_curve_to_path, 6);
rb_define_method(cFM, "close_path", FM_close_path, 0);
rb_define_method(cFM, "append_points_to_path", FM_append_points_to_path, 2);
rb_define_method(cFM, "private_append_points_with_gaps_to_path", FM_private_append_points_with_gaps_to_path, 4);
rb_define_method(cFM, "append_arc_to_path", FM_append_arc_to_path, 8);
@@ -510,17 +516,16 @@
rb_define_method(cFM, "no_left_edge", FM_no_left_edge, 0);
rb_define_method(cFM, "no_right_edge", FM_no_right_edge, 0);
rb_define_method(cFM, "no_top_edge", FM_no_top_edge, 0);
rb_define_method(cFM, "no_bottom_edge", FM_no_bottom_edge, 0);
/* makers */
- rb_define_method(cFM, "private_make_contour", FM_private_make_contour, 9);
- rb_define_method(cFM, "private_make_spline_interpolated_points", FM_private_make_spline_interpolated_points, 6);
- rb_define_method(cFM, "private_make_steps", FM_private_make_steps, 8);
+ rb_define_method(cFM, "private_make_contour", FM_private_make_contour, 7);
+ rb_define_method(cFM, "private_make_spline_interpolated_points", FM_private_make_spline_interpolated_points, 5);
+ rb_define_method(cFM, "private_make_steps", FM_private_make_steps, 6);
/* Title */
attr_reader(title_visible)
- attr_accessors(title)
attr_accessors(title_side)
attr_accessors(title_position)
attr_accessors(title_scale)
attr_accessors(title_shift)
attr_accessors(title_angle)
@@ -528,11 +533,10 @@
attr_accessors(title_justification)
attr_accessors(title_color)
/* X label */
attr_reader(xlabel_visible)
- attr_accessors(xlabel)
attr_accessors(xlabel_position)
attr_accessors(xlabel_scale)
attr_accessors(xlabel_shift)
attr_accessors(xlabel_angle)
attr_accessors(xlabel_side)
@@ -540,11 +544,10 @@
attr_accessors(xlabel_justification)
attr_accessors(xlabel_color)
/* Y label */
attr_reader(ylabel_visible)
- attr_accessors(ylabel)
attr_accessors(ylabel_position)
attr_accessors(ylabel_scale)
attr_accessors(ylabel_shift)
attr_accessors(ylabel_angle)
attr_accessors(ylabel_side)
@@ -566,15 +569,12 @@
attr_accessors(xaxis_ticks_inside)
attr_accessors(xaxis_ticks_outside)
attr_accessors(xaxis_tick_interval)
attr_accessors(xaxis_min_between_major_ticks)
attr_accessors(xaxis_number_of_minor_intervals)
- attr_accessors(xaxis_locations_for_major_ticks)
- attr_accessors(xaxis_locations_for_minor_ticks)
attr_accessors(xaxis_use_fixed_pt)
attr_accessors(xaxis_digits_max)
- attr_accessors(xaxis_tick_labels)
attr_accessors(xaxis_numeric_label_decimal_digits)
attr_accessors(xaxis_numeric_label_scale)
attr_accessors(xaxis_numeric_label_shift)
attr_accessors(xaxis_numeric_label_angle)
attr_accessors(xaxis_numeric_label_alignment)
@@ -600,15 +600,12 @@
attr_accessors(yaxis_ticks_inside)
attr_accessors(yaxis_ticks_outside)
attr_accessors(yaxis_tick_interval)
attr_accessors(yaxis_min_between_major_ticks)
attr_accessors(yaxis_number_of_minor_intervals)
- attr_accessors(yaxis_locations_for_major_ticks)
- attr_accessors(yaxis_locations_for_minor_ticks)
attr_accessors(yaxis_use_fixed_pt)
attr_accessors(yaxis_digits_max)
- attr_accessors(yaxis_tick_labels)
attr_accessors(yaxis_numeric_label_decimal_digits)
attr_accessors(yaxis_numeric_label_scale)
attr_accessors(yaxis_numeric_label_shift)
attr_accessors(yaxis_numeric_label_angle)
attr_accessors(yaxis_numeric_label_alignment)
@@ -634,15 +631,17 @@
attr_accessors(legend_justification)
/* Debugging */
attr_accessors(debug_verbosity_level)
+
+ Set_fm_data_size(); // must set this before create a FigureMaker instance
rb_require("Tioga/FigMkr.rb");
/* We now need to import the symbols */
/* imports from Dvector */
- VALUE cDvector = rb_define_class_under(mDobjects, "Dvector", rb_cObject);
+ OBJ_PTR cDvector = rb_define_class_under(mDobjects, "Dvector", rb_cObject);
RB_IMPORT_SYMBOL(cDvector, Dvector_Create);
RB_IMPORT_SYMBOL(cDvector, Dvector_Data_Resize);
RB_IMPORT_SYMBOL(cDvector, Dvector_Data_Replace);
RB_IMPORT_SYMBOL(cDvector, Dvector_Data_for_Read);
RB_IMPORT_SYMBOL(cDvector, Dvector_Data_for_Write);
@@ -654,10 +653,10 @@
/* imports from Flate */
RB_IMPORT_SYMBOL(mFlate, flate_compress);
RB_IMPORT_SYMBOL(mFlate, flate_expand);
/* imports from Dtable */
- VALUE cDtable = rb_define_class_under(mDobjects, "Dtable", rb_cObject);
+ OBJ_PTR cDtable = rb_define_class_under(mDobjects, "Dtable", rb_cObject);
RB_IMPORT_SYMBOL(cDtable, Dtable_Ptr);
RB_IMPORT_SYMBOL(cDtable, Read_Dtable);
}
/* implementation of the various functions */