Search in sources :

Example 1 with Align

use of org.eclipse.mylyn.wikitext.parser.ImageAttributes.Align in project mylyn.docs by eclipse.

the class HtmlDocumentBuilder method applyImageAttributes.

private void applyImageAttributes(Attributes attributes) {
    int border = 0;
    Align align = null;
    if (attributes instanceof ImageAttributes) {
        ImageAttributes imageAttributes = (ImageAttributes) attributes;
        border = imageAttributes.getBorder();
        align = imageAttributes.getAlign();
    }
    if (xhtmlStrict) {
        // $NON-NLS-1$
        String borderStyle = String.format("border-width: %spx;", border);
        String alignStyle = null;
        if (align != null) {
            switch(align) {
                case Center:
                case Right:
                case Left:
                    // $NON-NLS-1$ //$NON-NLS-2$
                    alignStyle = "text-align: " + align.name().toLowerCase() + ";";
                    break;
                case Bottom:
                case Baseline:
                case Top:
                case Middle:
                    // $NON-NLS-1$ //$NON-NLS-2$
                    alignStyle = "vertical-align: " + align.name().toLowerCase() + ";";
                    break;
                case Texttop:
                    // $NON-NLS-1$
                    alignStyle = "vertical-align: text-top;";
                    break;
                case Absmiddle:
                    // $NON-NLS-1$
                    alignStyle = "vertical-align: middle;";
                    break;
                case Absbottom:
                    // $NON-NLS-1$
                    alignStyle = "vertical-align: bottom;";
                    break;
            }
        }
        String additionalStyles = borderStyle;
        if (alignStyle != null) {
            additionalStyles += alignStyle;
        }
        if (attributes.getCssStyle() == null || attributes.getCssStyle().length() == 0) {
            attributes.setCssStyle(additionalStyles);
        } else {
            attributes.setCssStyle(additionalStyles + attributes.getCssStyle());
        }
    }
    applyAttributes(attributes);
    boolean haveAlt = false;
    if (attributes instanceof ImageAttributes) {
        ImageAttributes imageAttributes = (ImageAttributes) attributes;
        if (imageAttributes.getHeight() != -1) {
            String val = Integer.toString(imageAttributes.getHeight());
            if (imageAttributes.isHeightPercentage()) {
                // $NON-NLS-1$
                val += "%";
            }
            // $NON-NLS-1$
            writer.writeAttribute("height", val);
        }
        if (imageAttributes.getWidth() != -1) {
            String val = Integer.toString(imageAttributes.getWidth());
            if (imageAttributes.isWidthPercentage()) {
                // $NON-NLS-1$
                val += "%";
            }
            // $NON-NLS-1$
            writer.writeAttribute("width", val);
        }
        if (!xhtmlStrict && align != null) {
            // $NON-NLS-1$
            writer.writeAttribute("align", align.name().toLowerCase());
        }
        if (imageAttributes.getAlt() != null) {
            haveAlt = true;
            // $NON-NLS-1$
            writer.writeAttribute("alt", imageAttributes.getAlt());
        }
    }
    if (attributes.getTitle() != null) {
        // $NON-NLS-1$
        writer.writeAttribute("title", attributes.getTitle());
        if (!haveAlt) {
            haveAlt = true;
            // $NON-NLS-1$
            writer.writeAttribute("alt", attributes.getTitle());
        }
    }
    if (xhtmlStrict) {
        if (!haveAlt) {
            // XHTML requires img/@alt
            // $NON-NLS-1$ //$NON-NLS-2$
            writer.writeAttribute("alt", "");
        }
    } else {
        // only specify border attribute if it's not already specified in CSS
        // $NON-NLS-1$
        writer.writeAttribute("border", Integer.toString(border));
    }
}
Also used : Align(org.eclipse.mylyn.wikitext.parser.ImageAttributes.Align) ImageAttributes(org.eclipse.mylyn.wikitext.parser.ImageAttributes)

Aggregations

ImageAttributes (org.eclipse.mylyn.wikitext.parser.ImageAttributes)1 Align (org.eclipse.mylyn.wikitext.parser.ImageAttributes.Align)1