X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Ftext-editing.cpp;h=5b9db13d4532a29c2926344b9f5e0322133afa45;hb=c7f63721da16792f5aa959519d17158f1221ad13;hp=3c4b4da8e91e13f6f95fd62f8ecf3e63f3435a4f;hpb=b2e43080dc09f00ebc89919b1adbded5203e8ee1;p=inkscape.git diff --git a/src/text-editing.cpp b/src/text-editing.cpp index 3c4b4da8e..5b9db13d4 100644 --- a/src/text-editing.cpp +++ b/src/text-editing.cpp @@ -78,37 +78,45 @@ sp_te_input_is_empty (SPObject const *item) } Inkscape::Text::Layout::iterator -sp_te_get_position_by_coords (SPItem const *item, NR::Point &i_p) +sp_te_get_position_by_coords (SPItem const *item, Geom::Point const &i_p) { - NR::Matrix im = from_2geom(sp_item_i2d_affine (item)); + Geom::Matrix im (sp_item_i2d_affine (item)); im = im.inverse(); - NR::Point p = i_p * im; + Geom::Point p = i_p * im; Inkscape::Text::Layout const *layout = te_get_layout(item); return layout->getNearestCursorPositionTo(p); } -std::vector sp_te_create_selection_quads(SPItem const *item, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, NR::Matrix const &transform) +std::vector sp_te_create_selection_quads(SPItem const *item, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, Geom::Matrix const &transform) { if (start == end) - return std::vector(); + return std::vector(); Inkscape::Text::Layout const *layout = te_get_layout(item); if (layout == NULL) - return std::vector(); + return std::vector(); return layout->createSelectionShape(start, end, transform); } void -sp_te_get_cursor_coords (SPItem const *item, Inkscape::Text::Layout::iterator const &position, NR::Point &p0, NR::Point &p1) +sp_te_get_cursor_coords (SPItem const *item, Inkscape::Text::Layout::iterator const &position, Geom::Point &p0, Geom::Point &p1) { Inkscape::Text::Layout const *layout = te_get_layout(item); double height, rotation; - layout->queryCursorShape(position, &p0, &height, &rotation); - p1 = NR::Point(p0[NR::X] + height * sin(rotation), p0[NR::Y] - height * cos(rotation)); + layout->queryCursorShape(position, p0, height, rotation); + p1 = Geom::Point(p0[Geom::X] + height * sin(rotation), p0[Geom::Y] - height * cos(rotation)); } SPStyle const * sp_te_style_at_position(SPItem const *text, Inkscape::Text::Layout::iterator const &position) +{ + SPObject const *pos_obj = sp_te_object_at_position(text, position); + if (pos_obj) + return SP_OBJECT_STYLE(pos_obj); + return NULL; +} + +SPObject const * sp_te_object_at_position(SPItem const *text, Inkscape::Text::Layout::iterator const &position) { Inkscape::Text::Layout const *layout = te_get_layout(text); if (layout == NULL) @@ -119,8 +127,8 @@ SPStyle const * sp_te_style_at_position(SPItem const *text, Inkscape::Text::Layo pos_obj = SP_OBJECT(rawptr); if (pos_obj == 0) pos_obj = text; while (SP_OBJECT_STYLE(pos_obj) == NULL) - pos_obj = SP_OBJECT_PARENT(pos_obj); // SPStrings don't have style - return SP_OBJECT_STYLE(pos_obj); + pos_obj = SP_OBJECT_PARENT(pos_obj); // not interested in SPStrings + return pos_obj; } /* @@ -779,7 +787,7 @@ sp_te_delete (SPItem *item, Inkscape::Text::Layout::iterator const &start, } } - while (tidy_xml_tree_recursively(common_ancestor)); + while (tidy_xml_tree_recursively(common_ancestor)){}; te_update_layout_now(item); item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); layout->validateIterator(&iter_pair.first); @@ -943,13 +951,13 @@ text_tag_attributes_at_position(SPItem *item, Inkscape::Text::Layout::iterator c } void -sp_te_adjust_kerning_screen (SPItem *item, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, SPDesktop *desktop, NR::Point by) +sp_te_adjust_kerning_screen (SPItem *item, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, SPDesktop *desktop, Geom::Point by) { // divide increment by zoom // divide increment by matrix expansion gdouble factor = 1 / desktop->current_zoom(); - NR::Matrix t = from_2geom(sp_item_i2doc_affine(item)); - factor = factor / NR::expansion(t); + Geom::Matrix t (sp_item_i2doc_affine(item)); + factor = factor / t.descrim(); by = factor * by; unsigned char_index; @@ -970,8 +978,8 @@ sp_te_adjust_rotation_screen(SPItem *text, Inkscape::Text::Layout::iterator cons // divide increment by zoom // divide increment by matrix expansion gdouble factor = 1 / desktop->current_zoom(); - NR::Matrix t = from_2geom(sp_item_i2doc_affine(text)); - factor = factor / NR::expansion(t); + Geom::Matrix t (sp_item_i2doc_affine(text)); + factor = factor / t.descrim(); Inkscape::Text::Layout const *layout = te_get_layout(text); if (layout == NULL) return; SPObject *source_item = 0; @@ -1055,7 +1063,7 @@ sp_te_adjust_tspan_letterspacing_screen(SPItem *text, Inkscape::Text::Layout::it gdouble const zoom = desktop->current_zoom(); gdouble const zby = (by / (zoom * (nb_let > 1 ? nb_let - 1 : 1)) - / NR::expansion(from_2geom(sp_item_i2doc_affine(SP_ITEM(source_obj))))); + / to_2geom(sp_item_i2doc_affine(SP_ITEM(source_obj))).descrim()); val += zby; if (start == end) { @@ -1094,7 +1102,7 @@ sp_te_get_average_linespacing (SPItem *text) return 0; unsigned line_count = layout->lineIndex(layout->end()); - double all_lines_height = layout->characterAnchorPoint(layout->end())[NR::Y] - layout->characterAnchorPoint(layout->begin())[NR::Y]; + double all_lines_height = layout->characterAnchorPoint(layout->end())[Geom::Y] - layout->characterAnchorPoint(layout->begin())[Geom::Y]; double average_line_height = all_lines_height / (line_count == 0 ? 1 : line_count); return average_line_height; } @@ -1118,7 +1126,7 @@ sp_te_adjust_linespacing_screen (SPItem *text, Inkscape::Text::Layout::iterator } unsigned line_count = layout->lineIndex(layout->end()); - double all_lines_height = layout->characterAnchorPoint(layout->end())[NR::Y] - layout->characterAnchorPoint(layout->begin())[NR::Y]; + double all_lines_height = layout->characterAnchorPoint(layout->end())[Geom::Y] - layout->characterAnchorPoint(layout->begin())[Geom::Y]; double average_line_height = all_lines_height / (line_count == 0 ? 1 : line_count); if (fabs(average_line_height) < 0.001) average_line_height = 0.001; @@ -1127,8 +1135,8 @@ sp_te_adjust_linespacing_screen (SPItem *text, Inkscape::Text::Layout::iterator gdouble zby = by / (desktop->current_zoom() * (line_count == 0 ? 1 : line_count)); // divide increment by matrix expansion - NR::Matrix t = from_2geom(sp_item_i2doc_affine (SP_ITEM(text))); - zby = zby / NR::expansion(t); + Geom::Matrix t (sp_item_i2doc_affine (SP_ITEM(text))); + zby = zby / t.descrim(); switch (style->line_height.unit) { case SP_CSS_UNIT_NONE: @@ -1669,6 +1677,7 @@ static bool tidy_operator_styled_whitespace(SPObject **item) for ( ; ; ) { // go up one item in the xml test_item = SP_OBJECT_PARENT(test_item); if (is_line_break_object(test_item)) break; + if (SP_IS_FLOWTEXT(test_item)) return false; SPObject *next = SP_OBJECT_NEXT(test_item); if (next) { test_item = next; @@ -1796,9 +1805,24 @@ void sp_te_apply_style(SPItem *text, Inkscape::Text::Layout::iterator const &sta The recursion may involve creating new spans. */ SPObject *common_ancestor = get_common_ancestor(text, start_item, end_item); + + // bug #168370 (consider parent transform and viewBox) + // snipplet copied from desktop-style.cpp sp_desktop_apply_css_recursive(...) + SPCSSAttr *css_set = sp_repr_css_attr_new(); + sp_repr_css_merge(css_set, (SPCSSAttr*) css); + { + Geom::Matrix const local(sp_item_i2doc_affine(SP_ITEM(common_ancestor))); + double const ex(local.descrim()); + if ( ( ex != 0. ) + && ( ex != 1. ) ) { + sp_css_attr_scale(css_set, 1/ex); + } + } + start_item = ascend_while_first(start_item, start_text_iter, common_ancestor); end_item = ascend_while_first(end_item, end_text_iter, common_ancestor); - recursively_apply_style(common_ancestor, css, start_item, start_text_iter, end_item, end_text_iter, span_name_for_text_object(text)); + recursively_apply_style(common_ancestor, css_set, start_item, start_text_iter, end_item, end_text_iter, span_name_for_text_object(text)); + sp_repr_css_attr_unref(css_set); /* stage 2: cleanup the xml tree (of which there are multiple passes) */ /* discussion: this stage requires a certain level of inventiveness because @@ -1812,7 +1836,7 @@ void sp_te_apply_style(SPItem *text, Inkscape::Text::Layout::iterator const &sta and neither option can be made to work, a fallback could be to reduce everything to a single level of nesting and drop all pretence of roundtrippability. */ - while (tidy_xml_tree_recursively(common_ancestor)); + while (tidy_xml_tree_recursively(common_ancestor)){}; // if we only modified subobjects this won't have been automatically sent text->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);