summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Smith <john.smith7545@yahoo.com>2012-08-21 05:36:22 +0000
committerJohn Smith <john.smith7545@yahoo.com>2012-08-21 05:36:22 +0000
commitb3cb91168ba74ef510452d42697e322e27309691 (patch)
treedd58d410639ca242ff62e03ae7242beace6679a3 /src
parentfix type (fixes Windows build) (diff)
downloadinkscape-b3cb91168ba74ef510452d42697e322e27309691.tar.gz
inkscape-b3cb91168ba74ef510452d42697e322e27309691.zip
Fix for 168164 : Font size, always output px option
(bzr r11616)
Diffstat (limited to 'src')
-rw-r--r--src/style.cpp20
-rw-r--r--src/style.h3
-rw-r--r--src/ui/dialog/inkscape-preferences.cpp3
-rw-r--r--src/ui/dialog/inkscape-preferences.h1
-rw-r--r--src/ui/dialog/text-edit.cpp16
-rw-r--r--src/widgets/text-toolbar.cpp10
6 files changed, 41 insertions, 12 deletions
diff --git a/src/style.cpp b/src/style.cpp
index 5c343cdf1..1709132a0 100644
--- a/src/style.cpp
+++ b/src/style.cpp
@@ -2470,7 +2470,7 @@ sp_style_get_css_unit_string(int unit)
* Convert a size in pixels into another CSS unit size
*/
double
-sp_style_get_css_font_size_units(double size, int unit)
+sp_style_css_size_px_to_units(double size, int unit)
{
double unit_size = size;
switch (unit) {
@@ -2493,6 +2493,19 @@ sp_style_get_css_font_size_units(double size, int unit)
return unit_size;
}
+
+/*
+ * Convert a size in a CSS unit size to pixels
+ */
+double
+sp_style_css_size_units_to_px(double size, int unit)
+{
+ if (unit == SP_CSS_UNIT_PX) {
+ return size;
+ }
+ //g_message("sp_style_css_size_units_to_px %f %d = %f px", size, unit, out);
+ return size * (size / sp_style_css_size_px_to_units(size, unit));;
+}
/**
*
*/
@@ -4220,7 +4233,10 @@ sp_style_write_ifontsize(gchar *p, gint const len, gchar const *key,
Inkscape::CSSOStringStream os;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);
- os << key << ":" << sp_style_get_css_font_size_units(val->computed, unit) << sp_style_get_css_unit_string(unit) << ";";
+ if (prefs->getBool("/options/font/textOutputPx", false)) {
+ unit = SP_CSS_UNIT_PX;
+ }
+ os << key << ":" << sp_style_css_size_px_to_units(val->computed, unit) << sp_style_get_css_unit_string(unit) << ";";
return g_strlcpy(p, os.str().c_str(), len);
} else if (val->type == SP_FONT_SIZE_PERCENTAGE) {
Inkscape::CSSOStringStream os;
diff --git a/src/style.h b/src/style.h
index de32166fb..576167645 100644
--- a/src/style.h
+++ b/src/style.h
@@ -442,7 +442,8 @@ gchar *sp_style_write_difference(SPStyle const *from, SPStyle const *to);
void sp_style_set_to_uri_string (SPStyle *style, bool isfill, const gchar *uri);
gchar const *sp_style_get_css_unit_string(int unit);
-double sp_style_get_css_font_size_units(double size, int unit);
+double sp_style_css_size_px_to_units(double size, int unit);
+double sp_style_css_size_units_to_px(double size, int unit);
/* SPTextStyle */
diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp
index d72cde42e..fd5fd9fe1 100644
--- a/src/ui/dialog/inkscape-preferences.cpp
+++ b/src/ui/dialog/inkscape-preferences.cpp
@@ -445,9 +445,12 @@ void InkscapePreferences::initPageTools()
Glib::ustring sizeLabels[] = {_("Pixel"), _("Point"), _("Pica"), _("Millimeter"), _("Centimeter"), _("Inch"), _("Em square")/*, _("Ex square"), _("Percent")*/};
int sizeValues[] = {SP_CSS_UNIT_PX, SP_CSS_UNIT_PT, SP_CSS_UNIT_PC, SP_CSS_UNIT_MM, SP_CSS_UNIT_CM, SP_CSS_UNIT_IN, SP_CSS_UNIT_EM/*, SP_CSS_UNIT_EX, SP_CSS_UNIT_PERCENT*/};
+ _page_text.add_group_header( _("Text units"));
_font_unit_type.init( "/options/font/unitType", sizeLabels, sizeValues, G_N_ELEMENTS(sizeLabels), SP_CSS_UNIT_PT );
_page_text.add_line( false, _("Text size unit type:"), _font_unit_type, "",
_("Set the type of unit used in the text toolbar and text dialogs"), false);
+ _font_output_px.init ( _("Always output text size in pixels (px)"), "/options/font/textOutputPx", false);
+ _page_text.add_line( false, "", _font_output_px, "", _("Always convert the text size units above into pixels (px) before saving to file"));
this->AddNewObjectsStyle(_page_text, "/tools/text");
diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h
index c78eb08d8..094e6ee45 100644
--- a/src/ui/dialog/inkscape-preferences.h
+++ b/src/ui/dialog/inkscape-preferences.h
@@ -291,6 +291,7 @@ protected:
UI::Widget::PrefSlider _snap_weight;
UI::Widget::PrefCheckButton _font_dialog;
UI::Widget::PrefCombo _font_unit_type;
+ UI::Widget::PrefCheckButton _font_output_px;
UI::Widget::PrefCheckButton _misc_comment;
UI::Widget::PrefCheckButton _misc_default_metadata;
diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp
index 5a983fc1a..0ea67b630 100644
--- a/src/ui/dialog/text-edit.cpp
+++ b/src/ui/dialog/text-edit.cpp
@@ -55,6 +55,7 @@ extern "C" {
#include "widgets/icon.h"
#include "widgets/font-selector.h"
#include <glibmm/i18n.h>
+#include "unit-constants.h"
namespace Inkscape {
@@ -319,7 +320,7 @@ void TextEdit::onReadSelection ( gboolean dostyle, gboolean /*docontent*/ )
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);
- sp_font_selector_set_font (fsel, font, sp_style_get_css_font_size_units(query->font_size.computed, unit) );
+ sp_font_selector_set_font (fsel, font, sp_style_css_size_px_to_units(query->font_size.computed, unit) );
setPreviewText(font, phrase);
font->Unref();
font=NULL;
@@ -365,16 +366,15 @@ void TextEdit::setPreviewText (font_instance *font, Glib::ustring phrase)
}
char *desc = pango_font_description_to_string(font->descr);
- double unit_size = sp_font_selector_get_size(fsel);
-
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);
- double px_size = unit_size * (unit_size / sp_style_get_css_font_size_units(unit_size, unit));
+ double pt_size = sp_style_css_size_units_to_px(sp_font_selector_get_size(fsel), unit) * PT_PER_PX;
gchar *const phrase_escaped = g_markup_escape_text(phrase.c_str(), -1);
+ // Pango font size is in 1024ths of a point
gchar *markup = g_strdup_printf("<span font=\"%s\" size=\"%d\">%s</span>",
- desc, (int) (px_size * PANGO_SCALE), phrase_escaped);
+ desc, (int) (pt_size * PANGO_SCALE ), phrase_escaped);
preview_label.set_markup(markup);
@@ -469,7 +469,11 @@ SPCSSAttr *TextEdit::getTextStyle ()
Inkscape::CSSOStringStream os;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);
- os << sp_font_selector_get_size (fsel) << sp_style_get_css_unit_string(unit);
+ if (prefs->getBool("/options/font/textOutputPx", false)) {
+ os << sp_style_css_size_units_to_px(sp_font_selector_get_size (fsel), unit) << sp_style_get_css_unit_string(SP_CSS_UNIT_PX);
+ } else {
+ os << sp_font_selector_get_size (fsel) << sp_style_get_css_unit_string(unit);
+ }
sp_repr_css_set_property (css, "font-size", os.str().c_str());
font->Unref();
diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp
index b769c41f6..3d80008d8 100644
--- a/src/widgets/text-toolbar.cpp
+++ b/src/widgets/text-toolbar.cpp
@@ -445,10 +445,14 @@ static void sp_text_fontsize_value_changed( Ink_ComboBoxEntry_Action *act, GObje
size = max_size;
// Set css font size.
- int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);
SPCSSAttr *css = sp_repr_css_attr_new ();
Inkscape::CSSOStringStream osfs;
- osfs << size << sp_style_get_css_unit_string(unit);
+ int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);
+ if (prefs->getBool("/options/font/textOutputPx", false)) {
+ osfs << sp_style_css_size_units_to_px(size, unit) << sp_style_get_css_unit_string(SP_CSS_UNIT_PX);
+ } else {
+ osfs << size << sp_style_get_css_unit_string(unit);
+ }
sp_repr_css_set_property (css, "font-size", osfs.str().c_str());
// Apply font size to selected objects.
@@ -1218,7 +1222,7 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
// Size (average of text selected)
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);
- double size = sp_style_get_css_font_size_units(query->font_size.computed, unit);
+ double size = sp_style_css_size_px_to_units(query->font_size.computed, unit);
gchar size_text[G_ASCII_DTOSTR_BUF_SIZE];
g_ascii_dtostr (size_text, sizeof (size_text), size);