Logo Search packages:      
Sourcecode: inkscape version File versions

NR::Rect Inkscape::Text::Layout::characterBoundingBox ( iterator const &  it,
double *  rotation = NULL 
) const

Returns the box extents (not ink extents) of the given character. The centre of rotation is at the horizontal centre of the box on the text baseline.

Definition at line 249 of file Layout-TNG-OutIter.cpp.

References _blockProgression(), Inkscape::Text::Layout::iterator::_char_index, _directions_are_orthogonal(), Inkscape::Text::Layout::iterator::_glyph_index, _path_fitted, and NR::Point::cw().

Referenced by createSelectionShape(), and getLetterAt().

{
    NR::Point top_left, bottom_right;
    unsigned char_index = it._char_index;

    if (_path_fitted) {
        double cluster_half_width = 0.0;
        for (int glyph_index = _characters[char_index].in_glyph ; _glyphs[glyph_index].in_character == char_index ; glyph_index++)
            cluster_half_width += _glyphs[glyph_index].width;
        cluster_half_width *= 0.5;

        double midpoint_offset = _characters[char_index].span(this).x_start + _characters[char_index].x + cluster_half_width;
        int unused = 0;
        Path::cut_position *midpoint_otp = const_cast<Path*>(_path_fitted)->CurvilignToPosition(1, &midpoint_offset, unused);
        if (midpoint_offset >= 0.0 && midpoint_otp != NULL && midpoint_otp[0].piece >= 0) {
            NR::Point midpoint;
            NR::Point tangent;
            Span const &span = _characters[char_index].span(this);

            const_cast<Path*>(_path_fitted)->PointAndTangentAt(midpoint_otp[0].piece, midpoint_otp[0].t, midpoint, tangent);
            top_left[NR::X] = midpoint[NR::X] - cluster_half_width;
            top_left[NR::Y] = midpoint[NR::Y] - span.line_height.ascent;
            bottom_right[NR::X] = midpoint[NR::X] + cluster_half_width;
            bottom_right[NR::Y] = midpoint[NR::Y] + span.line_height.descent;
            NR::Point normal = tangent.cw();
            top_left += span.baseline_shift * normal;
            bottom_right += span.baseline_shift * normal;
            if (rotation)
                *rotation = atan2(tangent[1], tangent[0]);
        }
        g_free(midpoint_otp);
    } else {
        if (it._char_index == _characters.size()) {
            top_left[NR::X] = bottom_right[NR::X] = _chunks.back().left_x + _spans.back().x_end;
            char_index--;
        } else {
            double span_x = _spans[_characters[it._char_index].in_span].x_start + _characters[it._char_index].chunk(this).left_x;
            top_left[NR::X] = span_x + _characters[it._char_index].x;
            if (it._char_index + 1 == _characters.size() || _characters[it._char_index + 1].in_span != _characters[it._char_index].in_span)
                bottom_right[NR::X] = _spans[_characters[it._char_index].in_span].x_end + _characters[it._char_index].chunk(this).left_x;
            else
                bottom_right[NR::X] = span_x + _characters[it._char_index + 1].x;
        }

        double baseline_y = _characters[char_index].line(this).baseline_y + _characters[char_index].span(this).baseline_shift;
        if (_directions_are_orthogonal(_blockProgression(), TOP_TO_BOTTOM)) {
            double span_height = _spans[_characters[char_index].in_span].line_height.ascent + _spans[_characters[char_index].in_span].line_height.descent;
            top_left[NR::Y] = top_left[NR::X];
            top_left[NR::X] = baseline_y - span_height * 0.5;
            bottom_right[NR::Y] = bottom_right[NR::X];
            bottom_right[NR::X] = baseline_y + span_height * 0.5;
        } else {
            top_left[NR::Y] = baseline_y - _spans[_characters[char_index].in_span].line_height.ascent;
            bottom_right[NR::Y] = baseline_y + _spans[_characters[char_index].in_span].line_height.descent;
        }

        if (rotation) {
            if (it._glyph_index == -1)
                *rotation = 0.0;
            else if (it._glyph_index == (int)_glyphs.size())
                *rotation = _glyphs.back().rotation;
            else
                *rotation = _glyphs[it._glyph_index].rotation;
        }
    }

    return NR::Rect(top_left, bottom_right);
}


Generated by  Doxygen 1.6.0   Back to index