ruler.cpp revision a00d232ef8ecb04fb29c1c7ea67f8e14df15b309
#define __SP_RULER_C__
/*
* Customized ruler class for inkscape
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* Frank Felfe <innerspace@iname.com>
* bulia byak <buliabyak@users.sf.net>
*
* Copyright (C) 1999-2005 authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include <cmath>
#include <cstdio>
#include <string.h>
#include "widget-sizes.h"
#include "ruler.h"
#include "unit-constants.h"
#define MINIMUM_INCR 5
#define MAXIMUM_SUBDIVIDE 5
#define MAXIMUM_SCALES 10
sp_hruler_get_type (void)
{
static GtkType hruler_type = 0;
if (!hruler_type)
{
static const GtkTypeInfo hruler_info =
{
"SPHRuler",
sizeof (SPHRuler),
sizeof (SPHRulerClass),
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
};
}
return hruler_type;
}
static void
{
}
static void
{
}
sp_hruler_new (void)
{
}
static gint
{
gint x;
x = (int)event->x;
/* Make sure the ruler has been allocated already */
return FALSE;
}
static void
{
gint i, tick_index;
double increment; /* Number of pixels per unit */
double subd_incr;
if (!GTK_WIDGET_DRAWABLE (ruler))
return;
// Create the pango layout
0, 0,
return;
/* determine the scale
* 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 */
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
{
}
tick_index = 0;
{
/* draw label */
double label_spacing_px = (increment*(double)ruler->metric->ruler_scale[scale])/ruler->metric->subdivide[i];
if (i == 0 &&
{
else
}
/* 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;
cur = start + (((double)tick_index) * (double)ruler->metric->ruler_scale[scale])/ ruler->metric->subdivide[i];
}
}
}
static void
{
int i;
gint x, y;
if (GTK_WIDGET_DRAWABLE (ruler))
{
{
/* If a backing store exists, restore the ruler */
for (i = 0; i < bs_height; i++)
x + i, y + i,
x + bs_width - 1 - i, y + i);
}
}
}
// vruler
sp_vruler_get_type (void)
{
static GtkType vruler_type = 0;
if (!vruler_type)
{
static const GtkTypeInfo vruler_info =
{
"SPVRuler",
sizeof (SPVRuler),
sizeof (SPVRulerClass),
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
};
}
return vruler_type;
}
static void
{
}
static void
{
}
sp_vruler_new (void)
{
}
static gint
{
gint y;
y = (int)event->y;
/* Make sure the ruler has been allocated already */
return FALSE;
}
static void
{
gint i, j, tick_index;
double increment; /* Number of pixels per unit */
double subd_incr;
if (!GTK_WIDGET_DRAWABLE (ruler))
return;
// Create the pango layout
0, 0,
return;
/* 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.
*/
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
{
}
tick_index = 0;
/* draw label */
double label_spacing_px = fabs((increment*(double)ruler->metric->ruler_scale[scale])/ruler->metric->subdivide[i]);
if (i == 0 &&
{
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;
cur = start + (((double)tick_index) * (double)ruler->metric->ruler_scale[scale])/ ruler->metric->subdivide[i];
}
}
}
static void
{
int i;
gint x, y;
if (GTK_WIDGET_DRAWABLE (ruler))
{
{
/* If a backing store exists, restore the ruler */
for (i = 0; i < bs_width; i++)
x + i, y + i,
x + i, y + bs_height - 1 - i);
}
}
}
/// Ruler metrics.
static GtkRulerMetric const sp_ruler_metrics[] = {
// NOTE: the order of records in this struct must correspond to the SPMetric enum.
{"NONE", "", 1, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }},
{"millimeters", "mm", PX_PER_MM, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }},
{"centimeters", "cm", PX_PER_CM, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }},
};
void
{
if (metric == 0)
return;
if (GTK_WIDGET_DRAWABLE (ruler))
}