ruler.cpp revision 584e74d32e520855b500ecc8bdb6c661d2291ab6
/*
* Customized ruler class for inkscape
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* Frank Felfe <innerspace@iname.com>
* bulia byak <buliabyak@users.sf.net>
* Diederik van Lierop <mail@diedenrezi.nl>
* Jon A. Cruz <jon@joncruz.org>
*
* Copyright (C) 1999-2011 authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include <cstring>
#include <cmath>
#include <cstdio>
#include "widget-sizes.h"
#include "desktop-widget.h"
#include "ruler.h"
#include "unit-constants.h"
#include "round.h"
#define GTK_PARAM_READWRITE G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
#define MINIMUM_INCR 5
#define MAXIMUM_SUBDIVIDE 5
#define MAXIMUM_SCALES 10
#define ROUND(x) ((int) ((x) + 0.5))
enum {
};
typedef struct _GtkDeprecatedRulerPrivate GtkDeprecatedRulerPrivate;
struct _GtkDeprecatedRulerPrivate
{
};
GParamSpec *pspec);
GParamSpec *pspec);
static const GtkDeprecatedRulerMetric ruler_metrics[] =
{
{ "Pixel", "Pi", 1.0, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }},
{ "Inches", "In", 72.0, { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 }, { 1, 2, 4, 8, 16 }},
{ "Centimeters", "Cn", 28.35, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }},
};
#define GTK_DEPRECATED_RULER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_DEPRECATED_TYPE_RULER, GtkDeprecatedRulerPrivate))
NULL))
static void
{
"orientation");
g_param_spec_double ("lower",
_("Lower"),
_("Lower limit of ruler"),
0.0,
static_cast<GParamFlags>(GTK_PARAM_READWRITE)));
g_param_spec_double ("upper",
_("Upper"),
_("Upper limit of ruler"),
0.0,
static_cast<GParamFlags>(GTK_PARAM_READWRITE)));
g_param_spec_double ("position",
_("Position"),
_("Position of mark on the ruler"),
0.0,
static_cast<GParamFlags>(GTK_PARAM_READWRITE)));
g_param_spec_double ("max-size",
_("Max Size"),
_("Maximum size of the ruler"),
0.0,
static_cast<GParamFlags>(GTK_PARAM_READWRITE)));
/**
* GtkDeprecatedRuler:metric:
*
* The metric used for the ruler.
*/
g_param_spec_enum ("metric",
_("Metric"),
_("The metric used for the ruler"),
static_cast<GParamFlags>(GTK_PARAM_READWRITE)));
}
static void
{
ruler->slider_size = 0;
}
/**
* gtk_deprecated_ruler_set_range:
* @ruler: the gtkdeprecatedruler
* @lower: the lower limit of the ruler
* @upper: the upper limit of the ruler
* @position: the mark on the ruler
* @max_size: the maximum size of the ruler used when calculating the space to
* leave for the text
*
* This sets the range of the ruler.
*/
void
{
{
}
{
}
{
}
{
}
}
/**
* gtk_deprecated_ruler_get_range:
* @ruler: a #GtkDeprecatedRuler
* @lower: (allow-none): location to store lower limit of the ruler, or %NULL
* @upper: (allow-none): location to store upper limit of the ruler, or %NULL
* @position: (allow-none): location to store the current position of the mark on the ruler, or %NULL
* @max_size: location to store the maximum size of the ruler used when calculating
* the space to leave for the text, or %NULL.
*
* Retrieves values indicating the range and current position of a #GtkDeprecatedRuler.
* See gtk_deprecated_ruler_set_range().
**/
void
{
if (lower)
if (upper)
if (position)
if (max_size)
}
static void
{
switch (prop_id)
{
case PROP_ORIENTATION:
break;
case PROP_LOWER:
break;
case PROP_UPPER:
break;
case PROP_POSITION:
break;
case PROP_MAX_SIZE:
break;
case PROP_METRIC:
break;
default:
break;
}
}
static void
{
switch (prop_id)
{
case PROP_ORIENTATION:
break;
case PROP_LOWER:
break;
case PROP_UPPER:
break;
case PROP_POSITION:
break;
case PROP_MAX_SIZE:
break;
case PROP_METRIC:
break;
default:
break;
}
}
void
{
}
/**
* gtk_deprecated_ruler_get_metric:
* @ruler: a #GtkDeprecatedRuler
*
* Gets the units used for a #GtkDeprecatedRuler. See gtk_deprecated_ruler_set_metric().
*
* Return value: the units currently used for @ruler
**/
{
gint i;
for (i = 0; i < G_N_ELEMENTS (ruler_metrics); i++)
return static_cast<GtkMetricType>(i);
return static_cast<GtkMetricType>(0);
}
void
{
}
void
{
}
static void
{
widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
}
static void
{
if (ruler->backing_store)
{
}
}
static void
{
{
}
else
{
}
}
static void
{
if (gtk_widget_get_realized (widget))
{
allocation->x, allocation->y,
}
}
static gboolean
{
gint x;
gint y;
x = event->x;
y = event->y;
else
/* Make sure the ruler has been allocated already */
return FALSE;
}
static gboolean
{
if (gtk_widget_is_drawable (widget))
{
cairo_fill (cr);
cairo_destroy (cr);
}
return FALSE;
}
static void
{
if (ruler->backing_store)
{
return;
}
-1);
}
static void
{
gint i, j;
if (!gtk_widget_is_drawable (widget))
return;
digit_offset = ink_rect.y;
{
}
else
{
}
"hruler" : "vruler",
0, 0,
{
height + ythickness,
1);
}
else
{
height + xthickness,
1,
}
goto out;
/* determine the scale H
* We calculate the text size as for the vruler instead of using
* text_width = gdk_string_width(font, unit_str), so that the result
* for the scale looks consistent with an accompanying vruler
*/
/* determine the scale V
* use the maximum extents of the ruler to determine the largest
* possible number to be displayed. Calculate the height in pixels
* of this displayed text. Use this height to find a scale which
* leaves sufficient room for drawing the ruler.
*/
{
break;
}
else
{
break;
}
if (scale == MAXIMUM_SCALES)
/* drawing starts here */
length = 0;
for (i = MAXIMUM_SUBDIVIDE - 1; i >= 0; i--)
{
continue;
/* Calculate the length of the tickmarks. Make sure that
* this length increases for each set of ticks
*/
if (ideal_length > ++length)
{
}
else
{
}
{
{
1, length);
}
else
{
length, 1);
}
/* draw label */
if (i == 0)
{
{
NULL,
"hruler",
layout);
}
else
{
{
NULL,
"vruler",
xthickness + 1,
layout);
}
}
}
}
}
cairo_fill (cr);
out:
cairo_destroy (cr);
}
static void
{
gint x, y;
if (gtk_widget_is_drawable (widget))
{
{
}
else
{
}
{
/* If a backing store exists, restore the ruler */
if (ruler->backing_store)
{
cairo_fill (cr);
cairo_destroy (cr);
}
{
}
else
{
}
cairo_move_to (cr, x, y);
{
}
else
{
}
cairo_fill (cr);
cairo_destroy (cr);
}
}
}
#define UNUSED_PIXELS 2 // There appear to be two pixels that are not being used at each end of the ruler
static GtkWidgetClass *hruler_parent_class;
sp_hruler_get_type (void)
{
static GType hruler_type = 0;
if (!hruler_type)
{
static const GTypeInfo hruler_info = {
sizeof (SPHRulerClass),
sizeof (SPHRuler),
0,
};
hruler_type = g_type_register_static (gtk_deprecated_ruler_get_type (), "SPHRuler", &hruler_info, (GTypeFlags)0);
}
return hruler_type;
}
static void
{
}
static void
{
}
sp_hruler_new (void)
{
}
static gint
{
double x = event->x; //Although event->x is double according to the docs, it only appears to return integers
return FALSE;
}
// vruler
static GtkWidgetClass *vruler_parent_class;
sp_vruler_get_type (void)
{
static GType vruler_type = 0;
if (!vruler_type)
{
static const GTypeInfo vruler_info = {
sizeof (SPVRulerClass),
sizeof (SPVRuler),
0,
};
vruler_type = g_type_register_static (gtk_deprecated_ruler_get_type (), "SPVRuler", &vruler_info, (GTypeFlags)0);
}
return vruler_type;
}
static void
{
}
static void
{
}
sp_vruler_new (void)
{
}
static gint
{
double y = event->y; //Although event->y is double according to the docs, it only appears to return integers
return FALSE;
}
static void
{
}
static void
{
return;
gint digit_height = (int) floor (RULER_FONT_SIZE * RULER_FONT_VERTICAL_SPACING / PANGO_SCALE + 0.5);
if (orientation == GTK_ORIENTATION_HORIZONTAL) {
} else {
}
0, 0,
gdouble ruler_upper = 0;
gdouble ruler_lower = 0;
gdouble upper = ruler_upper / ruler->metric->pixels_per_unit; // upper and lower are expressed in ruler units
/* "pixels_per_unit" should be "points_per_unit". This is the size of the unit
* in 1/72nd's of an inch and has nothing to do with screen pixels */
return;
double increment = (double) (width + 2*UNUSED_PIXELS) / (upper - lower); // screen pixels per ruler unit
/* determine the scale
* For vruler, use the maximum extents of the ruler to determine the largest
* possible number to be displayed. Calculate the height in pixels
* of this displayed text. Use this height to find a scale which
* leaves sufficient room for drawing the ruler.
* For hruler, we calculate the text size as for the vruler instead of using
* text_width = gdk_string_width(font, unit_str), so that the result
* for the scale looks consistent with an accompanying vruler
*/
break;
if (scale == MAXIMUM_SCALES)
/* drawing starts here */
continue;
/* Calculate the length of the tickmarks. Make sure that
* this length increases for each set of ticks
*/
if (ideal_length > ++length)
} else {
}
gint tick_index = 0;
gdouble cur = start; // location (in ruler units) of the first invisible tick at the left side of the canvas
// due to the typical values for cur, lower and increment, pos will often end up to
// be e.g. 641.50000000000; rounding behaviour is not defined in such a case (see round.h)
// and jitter will be apparent (upon redrawing some of the lines on the ruler might jump a
// by a pixel, and jump back on the next redraw). This is suppressed by adding 1e-9 (that's only one nanopixel ;-))
if (orientation == GTK_ORIENTATION_HORIZONTAL) {
} else {
}
/* draw label */
double label_spacing_px = fabs((increment*(double)ruler->metric->ruler_scale[scale])/ruler->metric->subdivide[i]);
if (i == 0 &&
{
else
if (orientation == GTK_ORIENTATION_HORIZONTAL) {
} else {
xthickness + 1,
}
}
}
/* Calculate cur from start rather than incrementing by subd_incr
* in each iteration. This is to avoid propagation of floating point
* errors in subd_incr.
*/
++tick_index;
}
}
}
// Note: const casts are due to GtkDeprecatedRuler being const-broken and not scheduled for any more fixes.
/// Ruler metrics.
static GtkDeprecatedRulerMetric const sp_ruler_metrics[] = {
// NOTE: the order of records in this struct must correspond to the SPMetric enum.
{const_cast<gchar*>("NONE"), const_cast<gchar*>(""), 1, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }},
{const_cast<gchar*>("millimeters"), const_cast<gchar*>("mm"), PX_PER_MM, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }},
{const_cast<gchar*>("centimeters"), const_cast<gchar*>("cm"), PX_PER_CM, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }},
{const_cast<gchar*>("inches"), const_cast<gchar*>("in"), PX_PER_IN, { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 }, { 1, 2, 4, 8, 16 }},
{const_cast<gchar*>("feet"), const_cast<gchar*>("ft"), PX_PER_FT, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }},
{const_cast<gchar*>("points"), const_cast<gchar*>("pt"), PX_PER_PT, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }},
{const_cast<gchar*>("picas"), const_cast<gchar*>("pc"), PX_PER_PC, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }},
{const_cast<gchar*>("pixels"), const_cast<gchar*>("px"), PX_PER_PX, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }},
{const_cast<gchar*>("meters"), const_cast<gchar*>("m"), PX_PER_M, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }},
};
void
{
if (metric == 0)
return;
}