void sp_document_set_height (SPDocument * document, gdouble height, const SPUnit *unit)
{
    SPRoot *root = SP_ROOT(document->root);

    if (root->height.unit == SVGLength::PERCENT && root->viewBox_set) { // set to viewBox=
        root->viewBox.y1 = root->viewBox.y0 + sp_units_get_pixels (height, *unit);
    } else { // set to height=
        gdouble old_computed = root->height.computed;
        root->height.computed = sp_units_get_pixels (height, *unit);
        /* SVG does not support meters as a unit, so we must translate meters to
         * cm when writing */
        if (!strcmp(unit->abbr, "m")) {
            root->height.value = 100*height;
            root->height.unit = SVGLength::CM;
        } else {
            root->height.value = height;
            root->height.unit = (SVGLength::Unit) sp_unit_get_svg_unit(unit);
        }

        if (root->viewBox_set)
            root->viewBox.y1 = root->viewBox.y0 + (root->height.computed / old_computed) * (root->viewBox.y1 - root->viewBox.y0);
    }

    SP_OBJECT (root)->updateRepr();
}
Exemple #2
0
void GuidelinePropertiesDialog::_onApply()
{
    double deg_angle = _spin_angle.get_value();
    if (!_mode)
        deg_angle += _oldangle;
    Geom::Point normal;
    if ( deg_angle == 90. || deg_angle == 270. || deg_angle == -90. || deg_angle == -270.) {
        normal = Geom::Point(1.,0.);
    } else if ( deg_angle == 0. || deg_angle == 180. || deg_angle == -180.) {
        normal = Geom::Point(0.,1.);
    } else {
        double rad_angle = Geom::deg_to_rad( deg_angle );
        normal = Geom::rot90(Geom::Point::polar(rad_angle, 1.0));
    }
    sp_guide_set_normal(*_guide, normal, true);

    SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(_unit_selector->gobj()));
    gdouble const raw_dist_x = _spin_button_x.get_value();
    gdouble const points_x = sp_units_get_pixels(raw_dist_x, unit);
    gdouble const raw_dist_y = _spin_button_y.get_value();
    gdouble const points_y = sp_units_get_pixels(raw_dist_y, unit);
    Geom::Point newpos(points_x, points_y);
    if (!_mode)
        newpos += _oldpos;

    sp_guide_moveto(*_guide, newpos, true);

    sp_document_done(SP_OBJECT_DOCUMENT(_guide), SP_VERB_NONE, 
                     _("Set guide properties"));
}
void UnitTracker::_fixupAdjustments( SPUnit const* oldUnit, SPUnit const *newUnit )
{
    _isUpdating = true;
    for ( GSList* cur = _adjList; cur; cur = g_slist_next(cur) ) {
        GtkAdjustment* adj = GTK_ADJUSTMENT(cur->data);
        gdouble oldVal = gtk_adjustment_get_value(adj);
        gdouble val = oldVal;

        if ((oldUnit->base == SP_UNIT_ABSOLUTE || oldUnit->base == SP_UNIT_DEVICE)
            && (newUnit->base == SP_UNIT_DIMENSIONLESS))
        {
            val = 1.0 / newUnit->unittobase;
            _priorValues[adj] = sp_units_get_pixels( oldVal, *oldUnit );
        } else if ((oldUnit->base == SP_UNIT_DIMENSIONLESS)
                   && (newUnit->base == SP_UNIT_ABSOLUTE || newUnit->base == SP_UNIT_DEVICE)) {
            if ( _priorValues.find(adj) != _priorValues.end() ) {
                val = sp_pixels_get_units( _priorValues[adj], *newUnit );
            }
        } else {
            val = sp_convert_distance_full( oldVal, *oldUnit, *newUnit );
        }

        gtk_adjustment_set_value( adj, val );
    }
    _isUpdating = false;
}