Logo Search packages:      
Sourcecode: inkscape version File versions

int objects_query_fontnumbers ( GSList *  objects,
SPStyle style_res 
)

Write to style_res the average font size and spacing of objects.

Todo:
FIXME: add word spacing, kerns? rotates?

Todo:
FIXME: we assume non-% units here

Todo:
FIXME: we assume non-% units here

Definition at line 849 of file desktop-style.cpp.

References SPIEnum::computed, SPILengthOrNormal::computed, SPIFontSize::computed, SPStyle::font_size, SPStyle::letter_spacing, SPStyle::line_height, Inkscape::Text::Layout::LINE_HEIGHT_NORMAL, SPILengthOrNormal::normal, SPStyle::text_anchor, SPIFontSize::type, SPILengthOrNormal::unit, SPILengthOrNormal::value, and SPStyle::writing_mode.

Referenced by sp_desktop_query_style_from_list().

{
    bool different = false;

    double size = 0;
    double letterspacing = 0;
    double linespacing = 0;
    bool linespacing_normal = false;
    bool letterspacing_normal = false;

    double size_prev = 0;
    double letterspacing_prev = 0;
    double linespacing_prev = 0;

    /// \todo FIXME: add word spacing, kerns? rotates?

    int texts = 0;

    for (GSList const *i = objects; i != NULL; i = i->next) {
        SPObject *obj = SP_OBJECT (i->data);

        if (!SP_IS_TEXT(obj) && !SP_IS_FLOWTEXT(obj)
            && !SP_IS_TSPAN(obj) && !SP_IS_TREF(obj) && !SP_IS_TEXTPATH(obj)
            && !SP_IS_FLOWDIV(obj) && !SP_IS_FLOWPARA(obj) && !SP_IS_FLOWTSPAN(obj))
            continue;

        SPStyle *style = SP_OBJECT_STYLE (obj);
        if (!style) continue;

        texts ++;
        size += style->font_size.computed * NR::expansion(sp_item_i2d_affine(SP_ITEM(obj))); /// \todo FIXME: we assume non-% units here

        if (style->letter_spacing.normal) {
            if (!different && (letterspacing_prev == 0 || letterspacing_prev == letterspacing))
                letterspacing_normal = true;
        } else {
            letterspacing += style->letter_spacing.computed; /// \todo FIXME: we assume non-% units here
            letterspacing_normal = false;
        }

        double linespacing_current;
        if (style->line_height.normal) {
            linespacing_current = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL;
            if (!different && (linespacing_prev == 0 || linespacing_prev == linespacing_current))
                linespacing_normal = true;
        } else if (style->line_height.unit == SP_CSS_UNIT_PERCENT || style->font_size.computed == 0) {
            linespacing_current = style->line_height.value;
            linespacing_normal = false;
        } else { // we need % here
            linespacing_current = style->line_height.computed / style->font_size.computed;
            linespacing_normal = false;
        }
        linespacing += linespacing_current;

        if ((size_prev != 0 && style->font_size.computed != size_prev) ||
            (letterspacing_prev != 0 && style->letter_spacing.computed != letterspacing_prev) ||
            (linespacing_prev != 0 && linespacing_current != linespacing_prev)) {
            different = true;
        }

        size_prev = style->font_size.computed;
        letterspacing_prev = style->letter_spacing.computed;
        linespacing_prev = linespacing_current;

        // FIXME: we must detect MULTIPLE_DIFFERENT for these too
        style_res->text_anchor.computed = style->text_anchor.computed;
        style_res->writing_mode.computed = style->writing_mode.computed;
    }

    if (texts == 0)
        return QUERY_STYLE_NOTHING;

    if (texts > 1) {
        size /= texts;
        letterspacing /= texts;
        linespacing /= texts;
    }

    style_res->font_size.computed = size;
    style_res->font_size.type = SP_FONT_SIZE_LENGTH;

    style_res->letter_spacing.normal = letterspacing_normal;
    style_res->letter_spacing.computed = letterspacing;

    style_res->line_height.normal = linespacing_normal;
    style_res->line_height.computed = linespacing;
    style_res->line_height.value = linespacing;
    style_res->line_height.unit = SP_CSS_UNIT_PERCENT;

    if (texts > 1) {
        if (different) {
            return QUERY_STYLE_MULTIPLE_AVERAGED;
        } else {
            return QUERY_STYLE_MULTIPLE_SAME;
        }
    } else {
        return QUERY_STYLE_SINGLE;
    }
}


Generated by  Doxygen 1.6.0   Back to index