ruler.cpp revision e105b4c199ab76d27d909104dfc0db72b377547e
/*
* 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 ROUND(x) ((int) ((x) + 0.5))
/* All distances below are in 1/72nd's of an inch. (According to
* Adobe, that's a point, but points are really 1/72.27 in.)
*/
typedef struct
{
enum {
};
GParamSpec *pspec);
GParamSpec *pspec);
#if GTK_CHECK_VERSION(3,0,0)
#endif
#if !GTK_CHECK_VERSION(3,0,0)
#endif
#define SP_RULER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), SP_TYPE_RULER, SPRulerPrivate))
// Note: const casts are due to SPRuler being const-broken and not scheduled for any more fixes.
/// Ruler metrics.
static SPRulerMetric 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 }},
};
NULL))
static void
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
"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)));
/**
* SPRuler:metric:
*
* The metric used for the ruler.
*
* TODO: This should probably use g_param_spec_enum
*/
g_param_spec_uint("metric",
_("Metric"),
_("The metric used for the ruler"),
0, 8,
static_cast<GParamFlags>(GTK_PARAM_READWRITE)));
}
static void
{
}
/**
* sp_ruler_set_range:
* @ruler: the SPRuler
* @lower: the lower limit of the ruler
* @upper: the upper limit of 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
{
{
}
{
}
{
}
}
/**
* sp_ruler_get_range:
* @ruler: a #SPRuler
* @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
* @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 #SPRuler.
* See sp_ruler_set_range().
**/
void
{
if (lower)
if (upper)
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;
}
}
/**
* sp_ruler_get_metric:
* @ruler: a #SPRuler
*
* Gets the units used for a #SPRuler. See sp_ruler_set_metric().
*
* Return value: the units currently used for @ruler
**/
{
return static_cast<SPMetric>(i);
}
}
return static_cast<SPMetric>(0);
}
static void
{
attributes.x = allocation.x;
attributes.y = allocation.y;
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
}
static void
{
if (priv->backing_store)
{
}
{
}
if (priv->input_window)
{
}
}
static void
{
if (priv->input_window)
}
static void
{
if (priv->input_window)
}
static void
{
if (gtk_widget_get_realized (widget))
{
allocation->x, allocation->y,
if (resized)
}
}
static void
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
}
else
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
}
}
#if GTK_CHECK_VERSION(3,0,0)
static void
{
}
static void
{
}
#else
static gboolean
{
cairo_clip (cr);
cairo_destroy (cr);
return result;
}
#endif
static gboolean
{
return FALSE;
}
static void
{
if (priv->backing_store)
}
static void
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
gint x, y;
if (! gtk_widget_is_drawable (widget))
return;
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
}
else
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
}
{
allocation.x, allocation.y,
cairo_clip (cr);
/* If a backing store exists, restore the ruler */
if (priv->backing_store)
{
cairo_fill (cr);
}
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
}
else
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
}
#if GTK_CHECK_VERSION(3,0,0)
&color);
#else
#endif
cairo_move_to (cr, x, y);
{
}
else
{
}
cairo_fill (cr);
cairo_destroy (cr);
}
}
// FIXME: Figure out why this is different in Gtk+ 2 and Gtk+ 3
#if GTK_CHECK_VERSION(3,0,0)
# define UNUSED_PIXELS 0
#else
# define UNUSED_PIXELS 2 // There appear to be two pixels that are not being used at each end of the ruler
#endif
/**
* sp_ruler_new:
* @orientation: the ruler's orientation
*
* Creates a new ruler.
*
* Return value: a new #SPRuler widget.
*/
{
"orientation", orientation,
NULL));
}
static void
gdouble x,
gdouble y)
{
{
lower +
}
else
{
lower +
}
}
/**
* sp_ruler_set_position:
* @ruler: a #SPRuler
* @position: the position to set the ruler to
*
* This sets the position of the ruler.
*/
void
{
{
}
}
/**
* sp_ruler_get_position:
* @ruler: a #SPRuler
*
* Return value: the current position of the @ruler widget.
*/
{
}
static gboolean
{
return FALSE;
}
static void
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
gint i;
if (! gtk_widget_is_drawable (widget))
return;
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
digit_offset = ink_rect.y;
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
}
else
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
}
#if GTK_CHECK_VERSION(3,0,0)
&color);
{
1);
}
else
{
1,
}
#else
cairo_paint (cr);
{
height + ythickness,
1);
}
else
{
height + xthickness,
1,
}
#endif
/* "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 */
goto out;
/* determine the scale
* 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.
*
* We calculate the text size as for the vruler instead of
* actually measuring the text width, so that the result for the
* scale looks consistent with an accompanying vruler
*/
break;
/* drawing starts here */
length = 0;
{
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;
{
// 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 GTK_CHECK_VERSION(3,0,0)
{
1, length);
}
else
{
length, 1);
}
#else
{
1, length);
}
else
{
length, 1);
}
#endif
/* draw label */
double label_spacing_px = fabs((increment*(double)priv->metric->ruler_scale[scale])/priv->metric->subdivide[i]);
if (i == 0 &&
{
else
{
#if GTK_CHECK_VERSION(3,0,0)
pos + 2,
#else
pos + 2,
#endif
}
else
{
gint j;
{
#if GTK_CHECK_VERSION(3,0,0)
#else
xthickness + 1,
#endif
}
}
}
++tick_index;
}
}
cairo_fill (cr);
out:
cairo_destroy (cr);
}
void
{
if (metric == 0)
return;
}
static PangoLayout*
{
attrs = pango_attr_list_new ();
attr->start_index = 0;
return layout;
}
static PangoLayout *
{
{
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :