From c5ad14e3e964f997e716953743842f01274a2993 Mon Sep 17 00:00:00 2001 From: cilix42 Date: Sun, 3 Feb 2008 14:56:48 +0000 Subject: [PATCH] Make units pc (pica) and ft (feet) work correctly. Closes: LP #167943. --- src/helper/units.cpp | 2 ++ src/helper/units.h | 2 ++ src/sp-metric.h | 2 ++ src/sp-metrics.cpp | 12 ++++++++++++ src/svg/svg-length.cpp | 10 +++++++++- src/svg/svg-length.h | 1 + src/unit-constants.h | 8 ++++++++ src/widgets/ruler.cpp | 4 +++- src/widgets/ruler.h | 3 +-- 9 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/helper/units.cpp b/src/helper/units.cpp index a78f5e623..3e632a0ca 100644 --- a/src/helper/units.cpp +++ b/src/helper/units.cpp @@ -36,6 +36,7 @@ SPUnit const sp_units[] = { {SP_UNIT_SCALE, SP_UNIT_DIMENSIONLESS, 1.0, NONE, SVGLength::NONE, N_("Unit"), "", N_("Units"), ""}, {SP_UNIT_PT, SP_UNIT_ABSOLUTE, PX_PER_PT, SP_PT, SVGLength::PT, N_("Point"), N_("pt"), N_("Points"), N_("Pt")}, + {SP_UNIT_PC, SP_UNIT_ABSOLUTE, PX_PER_PC, SP_PC, SVGLength::PC, N_("Pica"), N_("pc"), N_("Picas"), N_("Pc")}, {SP_UNIT_PX, SP_UNIT_DEVICE, PX_PER_PX, SP_PX, SVGLength::PX, N_("Pixel"), N_("px"), N_("Pixels"), N_("Px")}, /* You can add new elements from this point forward */ {SP_UNIT_PERCENT, SP_UNIT_DIMENSIONLESS, 0.01, NONE, SVGLength::PERCENT, N_("Percent"), N_("%"), N_("Percents"), N_("%")}, @@ -43,6 +44,7 @@ SPUnit const sp_units[] = { {SP_UNIT_CM, SP_UNIT_ABSOLUTE, PX_PER_CM, SP_CM, SVGLength::CM, N_("Centimeter"), N_("cm"), N_("Centimeters"), N_("cm")}, {SP_UNIT_M, SP_UNIT_ABSOLUTE, PX_PER_M, SP_M, SVGLength::NONE, N_("Meter"), N_("m"), N_("Meters"), N_("m")}, // no svg_unit {SP_UNIT_IN, SP_UNIT_ABSOLUTE, PX_PER_IN, SP_IN, SVGLength::INCH, N_("Inch"), N_("in"), N_("Inches"), N_("in")}, + {SP_UNIT_FT, SP_UNIT_ABSOLUTE, PX_PER_FT, SP_FT, SVGLength::FOOT, N_("Foot"), N_("ft"), N_("Feet"), N_("ft")}, /* Volatiles do not have default, so there are none here */ // TRANSLATORS: for info, see http://www.w3.org/TR/REC-CSS2/syndata.html#length-units {SP_UNIT_EM, SP_UNIT_VOLATILE, 1.0, NONE, SVGLength::EM, N_("Em square"), N_("em"), N_("Em squares"), N_("em")}, diff --git a/src/helper/units.h b/src/helper/units.h index 3acb65828..8dc62fee6 100644 --- a/src/helper/units.h +++ b/src/helper/units.h @@ -62,6 +62,7 @@ enum SPUnitBase { enum SPUnitId { SP_UNIT_SCALE, // 1.0 == 100% SP_UNIT_PT, // Postscript points: exactly 72 per inch + SP_UNIT_PC, // Pica; there are 12 points per pica SP_UNIT_PX, // "Pixels" in the CSS sense; though Inkscape assumes a constant 90 per inch. SP_UNIT_PERCENT, /* Note: In Inkscape this often means "relative to current value" (for users to edit a value), rather than the SVG/CSS use of percentages. */ @@ -69,6 +70,7 @@ enum SPUnitId { SP_UNIT_CM, // centimetres SP_UNIT_M, // metres SP_UNIT_IN, // inches + SP_UNIT_FT, // foot SP_UNIT_EM, // font-size of relevant font SP_UNIT_EX, // x-height of relevant font sp_max_unit_id = SP_UNIT_EX // For bounds-checking in sp_unit_get_by_id. diff --git a/src/sp-metric.h b/src/sp-metric.h index 76db44710..644c2c8eb 100644 --- a/src/sp-metric.h +++ b/src/sp-metric.h @@ -7,7 +7,9 @@ enum SPMetric { SP_MM, SP_CM, SP_IN, + SP_FT, SP_PT, + SP_PC, SP_PX, SP_M }; diff --git a/src/sp-metrics.cpp b/src/sp-metrics.cpp index 5f05c9fad..e3d8c3fe1 100644 --- a/src/sp-metrics.cpp +++ b/src/sp-metrics.cpp @@ -25,9 +25,15 @@ sp_absolute_metric_to_metric (gdouble length_src, const SPMetric metric_src, con case SP_IN: src = IN_PER_IN; break; + case SP_FT: + src = FT_PER_IN; + break; case SP_PT: src = PT_PER_IN; break; + case SP_PC: + src = PC_PER_IN; + break; case SP_PX: src = PX_PER_IN; break; @@ -49,9 +55,15 @@ sp_absolute_metric_to_metric (gdouble length_src, const SPMetric metric_src, con case SP_IN: dst = IN_PER_IN; break; + case SP_FT: + dst = FT_PER_IN; + break; case SP_PT: dst = PT_PER_IN; break; + case SP_PC: + dst = PC_PER_IN; + break; case SP_PX: dst = PX_PER_IN; break; diff --git a/src/svg/svg-length.cpp b/src/svg/svg-length.cpp index f0b7f85f6..f90944667 100644 --- a/src/svg/svg-length.cpp +++ b/src/svg/svg-length.cpp @@ -350,7 +350,7 @@ static unsigned sp_svg_length_read_lff(gchar const *str, SVGLength::Unit *unit, *unit = SVGLength::PC; } if (computed) { - *computed = v * 12 * PX_PER_PT; + *computed = v * PX_PER_PC; } break; case UVAL('m','m'): @@ -377,6 +377,14 @@ static unsigned sp_svg_length_read_lff(gchar const *str, SVGLength::Unit *unit, *computed = v * PX_PER_IN; } break; + case UVAL('f','t'): + if (unit) { + *unit = SVGLength::FOOT; + } + if (computed) { + *computed = v * PX_PER_FT; + } + break; case UVAL('e','m'): if (unit) { *unit = SVGLength::EM; diff --git a/src/svg/svg-length.h b/src/svg/svg-length.h index 883657494..d4e3334c6 100644 --- a/src/svg/svg-length.h +++ b/src/svg/svg-length.h @@ -27,6 +27,7 @@ public: MM, CM, INCH, + FOOT, EM, EX, PERCENT diff --git a/src/unit-constants.h b/src/unit-constants.h index f74207cf7..c56c0a6e8 100644 --- a/src/unit-constants.h +++ b/src/unit-constants.h @@ -8,8 +8,11 @@ #define PT_PER_IN 72.0 #define PT_PER_PX DEVICESCALE +#define PT_PER_PC 12.0 #define PX_PER_PT (1/DEVICESCALE) +#define PX_PER_PC (PX_PER_PT * PT_PER_PC) #define PX_PER_IN (PT_PER_IN / PT_PER_PX) +#define PC_PER_IN (PT_PER_IN / PT_PER_PC) #define M_PER_IN 0.0254 #define M_PER_PX (M_PER_IN / PX_PER_IN) #define CM_PER_IN 2.54 @@ -21,6 +24,8 @@ #define IN_PER_PX (1 / PX_PER_IN) #define IN_PER_CM (1 / CM_PER_IN) #define IN_PER_MM (1 / MM_PER_IN) +#define IN_PER_FT 12.0 +#define FT_PER_IN (1 / IN_PER_FT) #define PT_PER_CM (PT_PER_IN / CM_PER_IN) #define PX_PER_CM (PX_PER_IN / CM_PER_IN) #define M_PER_PT (M_PER_IN / PT_PER_IN) @@ -32,8 +37,11 @@ #define PT_PER_MM (PT_PER_IN / MM_PER_IN) #define PX_PER_MM (PX_PER_IN / MM_PER_IN) #define MM_PER_PX (MM_PER_IN / PX_PER_IN) +#define PX_PER_FT (PX_PER_IN / FT_PER_IN) #define PT_PER_PT 1.0 +#define PC_PER_PC 1.0 #define IN_PER_IN 1.0 #define PX_PER_PX 1.0 +#define FT_PER_FT 1.0 #endif /* !INKSCAPE_UNIT_CONSTANTS_H */ diff --git a/src/widgets/ruler.cpp b/src/widgets/ruler.cpp index 597034faf..b0037578d 100644 --- a/src/widgets/ruler.cpp +++ b/src/widgets/ruler.cpp @@ -707,9 +707,11 @@ static GtkRulerMetric const sp_ruler_metrics[] = { {"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 }}, {"inches", "in", PX_PER_IN, { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 }, { 1, 2, 4, 8, 16 }}, + {"feet", "ft", PX_PER_FT, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, {"points", "pt", PX_PER_PT, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, + {"picas", "pc", PX_PER_PC, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, {"pixels", "px", PX_PER_PX, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, - {"meters", "m", PX_PER_M, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, + {"meters", "m", PX_PER_M, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, }; void diff --git a/src/widgets/ruler.h b/src/widgets/ruler.h index 8aa162940..e2ea7c7fe 100644 --- a/src/widgets/ruler.h +++ b/src/widgets/ruler.h @@ -15,9 +15,8 @@ #include #include "sp-metric.h" -#include -#include +#include void sp_ruler_set_metric (GtkRuler * ruler, SPMetric metric); -- 2.30.2