~ubuntu-branches/ubuntu/utopic/inkscape/utopic-proposed

« back to all changes in this revision

Viewing changes to src/sp-text.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alex Valavanis
  • Date: 2010-09-12 19:44:58 UTC
  • mfrom: (1.1.12 upstream) (45.1.3 maverick)
  • Revision ID: james.westby@ubuntu.com-20100912194458-4sjwmbl7dlsrk5dc
Tags: 0.48.0-1ubuntu1
* Merge with Debian unstable (LP: #628048, LP: #401567, LP: #456248, 
  LP: #463602, LP: #591986)
* debian/control: 
  - Ubuntu maintainers
  - Promote python-lxml, python-numpy, python-uniconvertor to Recommends.
  - Demote pstoedit to Suggests (universe package).
  - Suggests ttf-dejavu instead of ttf-bitstream-vera (LP: #513319)
* debian/rules:
  - Run intltool-update on build (Ubuntu-specific).
  - Add translation domain to .desktop files (Ubuntu-specific).
* debian/dirs:
  - Add usr/share/pixmaps.  Allow inkscape.xpm installation
* drop 50-poppler-API.dpatch (now upstream)
* drop 51-paste-in-unwritable-directory.dpatch (now upstream) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
static NRArenaItem *sp_text_show (SPItem *item, NRArena *arena, unsigned key, unsigned flags);
75
75
static void sp_text_hide (SPItem *item, unsigned key);
76
76
static char *sp_text_description (SPItem *item);
77
 
static void sp_text_snappoints(SPItem const *item, bool const target, SnapPointsWithType &p, Inkscape::SnapPreferences const *snapprefs);
 
77
static void sp_text_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs);
78
78
static Geom::Matrix sp_text_set_transform(SPItem *item, Geom::Matrix const &xform);
79
79
static void sp_text_print (SPItem *item, SPPrintContext *gpc);
80
80
 
421
421
 
422
422
    GString *xs = SP_PX_TO_METRIC_STRING(style->font_size.computed, sp_desktop_namedview(SP_ACTIVE_DESKTOP)->getDefaultMetric());
423
423
 
 
424
    char const *trunc = "";
 
425
    Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) item);
 
426
    if (layout && layout->inputTruncated()) {
 
427
        trunc = _(" [truncated]");
 
428
    }
 
429
 
424
430
    char *ret = ( SP_IS_TEXT_TEXTPATH(item)
425
 
                  ? g_strdup_printf(_("<b>Text on path</b> (%s, %s)"), n, xs->str)
426
 
                  : g_strdup_printf(_("<b>Text</b> (%s, %s)"), n, xs->str) );
 
431
                  ? g_strdup_printf(_("<b>Text on path</b>%s (%s, %s)"), trunc, n, xs->str)
 
432
                  : g_strdup_printf(_("<b>Text</b>%s (%s, %s)"), trunc, n, xs->str) );
427
433
    g_free(n);
428
434
    return ret;
429
435
}
430
436
 
431
 
static void sp_text_snappoints(SPItem const *item, bool const target, SnapPointsWithType &p, Inkscape::SnapPreferences const */*snapprefs*/)
 
437
static void sp_text_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const */*snapprefs*/)
432
438
{
433
 
    // the baseline anchor of the first char
 
439
    // Choose a point on the baseline for snapping from or to, with the horizontal position
 
440
    // of this point depending on the text alignment (left vs. right)
434
441
    Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) item);
435
 
    if(layout != NULL) {
436
 
        int type = target ? int(Inkscape::SNAPTARGET_TEXT_BASELINE) : int(Inkscape::SNAPSOURCE_TEXT_BASELINE);
437
 
        p.push_back(std::make_pair(layout->characterAnchorPoint(layout->begin()) * sp_item_i2d_affine(item), type));
 
442
    if (layout != NULL && layout->outputExists()) {
 
443
        boost::optional<Geom::Point> pt = layout->baselineAnchorPoint();
 
444
        if (pt) {
 
445
            p.push_back(Inkscape::SnapCandidatePoint((*pt) * sp_item_i2d_affine(item), Inkscape::SNAPSOURCE_TEXT_BASELINE, Inkscape::SNAPTARGET_TEXT_BASELINE));
 
446
        }
438
447
    }
439
448
}
440
449
 
519
528
    }
520
529
    else if (SP_IS_TSPAN(root)) {
521
530
        SPTSpan *tspan = SP_TSPAN(root);
 
531
        // x, y attributes are stripped from some tspans marked with role="line" as we do our own line layout.
 
532
        // This should be checked carefully, as it can undo line layout in imported SVG files.
522
533
        bool use_xy = !in_textpath && (tspan->role == SP_TSPAN_ROLE_UNSPECIFIED || !tspan->attributes.singleXYCoordinates());
523
534
        tspan->attributes.mergeInto(&optional_attrs, parent_optional_attrs, parent_attrs_offset, use_xy, true);
524
535
    }
917
928
        *it = it->computed * scale_y;
918
929
}
919
930
 
 
931
double TextTagAttributes::getDx(unsigned index)
 
932
{
 
933
    if( attributes.dx.size() == 0 ) {
 
934
        return 0.0;
 
935
    }
 
936
    if( index < attributes.dx.size() ) {
 
937
        return attributes.dx[index].computed;
 
938
    } else {
 
939
        return 0.0; // attributes.dx.back().computed;
 
940
    }
 
941
}
 
942
 
 
943
 
 
944
double TextTagAttributes::getDy(unsigned index)
 
945
{
 
946
    if( attributes.dy.size() == 0 ) {
 
947
        return 0.0;
 
948
    }
 
949
    if( index < attributes.dy.size() ) {
 
950
        return attributes.dy[index].computed;
 
951
    } else {
 
952
        return 0.0; // attributes.dy.back().computed;
 
953
    }
 
954
}
 
955
 
 
956
 
 
957
void TextTagAttributes::addToDx(unsigned index, double delta)
 
958
{
 
959
    SVGLength zero_length;
 
960
    zero_length = 0.0;
 
961
 
 
962
    if (attributes.dx.size() < index + 1) attributes.dx.resize(index + 1, zero_length);
 
963
    attributes.dx[index] = attributes.dx[index].computed + delta;
 
964
}
 
965
 
 
966
void TextTagAttributes::addToDy(unsigned index, double delta)
 
967
{
 
968
    SVGLength zero_length;
 
969
    zero_length = 0.0;
 
970
 
 
971
    if (attributes.dy.size() < index + 1) attributes.dy.resize(index + 1, zero_length);
 
972
    attributes.dy[index] = attributes.dy[index].computed + delta;
 
973
}
 
974
 
920
975
void TextTagAttributes::addToDxDy(unsigned index, Geom::Point const &adjust)
921
976
{
922
977
    SVGLength zero_length;
932
987
    }
933
988
}
934
989
 
 
990
double TextTagAttributes::getRotate(unsigned index)
 
991
{
 
992
    if( attributes.rotate.size() == 0 ) {
 
993
        return 0.0;
 
994
    }
 
995
    if( index < attributes.rotate.size() ) {
 
996
        return attributes.rotate[index].computed;
 
997
    } else {
 
998
        return attributes.rotate.back().computed;
 
999
    }
 
1000
}
 
1001
 
 
1002
 
935
1003
void TextTagAttributes::addToRotate(unsigned index, double delta)
936
1004
{
937
1005
    SVGLength zero_length;
947
1015
}
948
1016
 
949
1017
 
 
1018
void TextTagAttributes::setRotate(unsigned index, double angle)
 
1019
{
 
1020
    SVGLength zero_length;
 
1021
    zero_length = 0.0;
 
1022
 
 
1023
    if (attributes.rotate.size() < index + 2) {
 
1024
        if (attributes.rotate.empty())
 
1025
            attributes.rotate.resize(index + 2, zero_length);
 
1026
        else
 
1027
            attributes.rotate.resize(index + 2, attributes.rotate.back());
 
1028
    }
 
1029
    attributes.rotate[index] = mod360(angle);
 
1030
}
 
1031
 
 
1032
 
950
1033
/*
951
1034
  Local Variables:
952
1035
  mode:c++