Search in sources :

Example 16 with ImageAttributes

use of org.eclipse.mylyn.wikitext.parser.ImageAttributes 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)

Example 17 with ImageAttributes

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

the class XslfoDocumentBuilder method applyImageAttributes.

private void applyImageAttributes(Attributes attributes) {
    boolean sizeSpecified = false;
    boolean scaleToFit = true;
    if (attributes instanceof ImageAttributes) {
        ImageAttributes imageAttributes = (ImageAttributes) attributes;
        if (imageAttributes.getWidth() > 0) {
            sizeSpecified = true;
            // $NON-NLS-1$
            emitImageSize("width", imageAttributes.getWidth(), imageAttributes.isWidthPercentage());
        }
        if (imageAttributes.getHeight() > 0) {
            sizeSpecified = true;
            // $NON-NLS-1$
            emitImageSize("height", imageAttributes.getHeight(), imageAttributes.isHeightPercentage());
        }
    }
    if (!sizeSpecified) {
        // $NON-NLS-1$ //$NON-NLS-2$
        writer.writeAttribute("width", "100%");
        // $NON-NLS-1$ //$NON-NLS-2$
        writer.writeAttribute("content-height", "100%");
    }
    if (scaleToFit) {
        // $NON-NLS-1$ //$NON-NLS-2$
        writer.writeAttribute("content-width", "scale-to-fit");
        // $NON-NLS-1$ //$NON-NLS-2$
        writer.writeAttribute("scaling", "uniform");
    }
}
Also used : ImageAttributes(org.eclipse.mylyn.wikitext.parser.ImageAttributes)

Example 18 with ImageAttributes

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

the class SplittingHtmlDocumentBuilder method emitNavigation.

private void emitNavigation(boolean header) {
    String currentName = currentFile.getName();
    List<SplitOutlineItem> pageOrder = outline.getPageOrder();
    SplitOutlineItem previous = null;
    SplitOutlineItem next = null;
    SplitOutlineItem current = null;
    boolean foundPage = false;
    for (SplitOutlineItem page : pageOrder) {
        if (page.getSplitTarget().equals(currentName)) {
            foundPage = true;
            current = page;
        } else if (!foundPage) {
            previous = page;
        } else {
            next = page;
            break;
        }
    }
    boolean rootPage = rootFile.getName().equals(currentFile.getName());
    if (next == null && previous == null && rootPage) {
        return;
    }
    if (!header) {
        // $NON-NLS-1$
        out.charactersUnescaped("<hr class=\"navigation-separator\"/>");
    }
    TableAttributes tableAttributes = new TableAttributes();
    // $NON-NLS-1$
    tableAttributes.setCssClass("navigation");
    // $NON-NLS-1$
    tableAttributes.setCssStyle("width: 100%;");
    // $NON-NLS-1$
    tableAttributes.setBorder("0");
    // $NON-NLS-1$
    tableAttributes.setSummary("navigation");
    out.beginBlock(BlockType.TABLE, tableAttributes);
    TableCellAttributes tableCellAttributes;
    if (header) {
        // header row, emit title of page
        out.beginBlock(BlockType.TABLE_ROW, new Attributes());
        tableCellAttributes = new TableCellAttributes();
        // $NON-NLS-1$
        tableCellAttributes.setAlign("center");
        // $NON-NLS-1$
        tableCellAttributes.setCssStyle("width: 100%");
        // $NON-NLS-1$
        tableCellAttributes.setColspan("3");
        out.beginBlock(BlockType.TABLE_CELL_HEADER, tableCellAttributes);
        if (rootPage) {
            out.characters(rootBuilder.getTitle());
        } else {
            // $NON-NLS-1$
            out.characters(current == null ? "" : current.getLabel());
        }
        out.endBlock();
        out.endBlock();
    }
    // navigation row
    out.beginBlock(BlockType.TABLE_ROW, new Attributes());
    LinkAttributes linkAttributes;
    tableCellAttributes = new TableCellAttributes();
    // $NON-NLS-1$
    tableCellAttributes.setAlign("left");
    // $NON-NLS-1$
    tableCellAttributes.setCssStyle("width: 20%");
    out.beginBlock(BlockType.TABLE_CELL_NORMAL, tableCellAttributes);
    if (previous != null) {
        linkAttributes = new LinkAttributes();
        linkAttributes.setTitle(previous.getLabel());
        if (navigationImages) {
            ImageAttributes imageAttributes = new ImageAttributes();
            // $NON-NLS-1$
            imageAttributes.setAlt(Messages.getString("SplittingHtmlDocumentBuilder.Previous"));
            out.imageLink(linkAttributes, imageAttributes, previous.getSplitTarget(), // $NON-NLS-1$
            computeNavImagePath(Messages.getString("SplittingHtmlDocumentBuilder.Previous_Image")));
        } else {
            out.link(linkAttributes, previous.getSplitTarget(), // $NON-NLS-1$
            Messages.getString("SplittingHtmlDocumentBuilder.Previous"));
        }
    }
    out.endBlock();
    tableCellAttributes = new TableCellAttributes();
    // $NON-NLS-1$
    tableCellAttributes.setAlign("center");
    // $NON-NLS-1$
    tableCellAttributes.setCssStyle("width: 60%");
    out.beginBlock(BlockType.TABLE_CELL_NORMAL, tableCellAttributes);
    if (!header && !rootPage) {
        linkAttributes = new LinkAttributes();
        linkAttributes.setTitle(rootBuilder.getTitle());
        if (navigationImages) {
            ImageAttributes imageAttributes = new ImageAttributes();
            imageAttributes.setAlt(rootBuilder.getTitle());
            out.imageLink(linkAttributes, imageAttributes, rootFile.getName(), // $NON-NLS-1$
            computeNavImagePath(Messages.getString("SplittingHtmlDocumentBuilder.Home_Image")));
        } else {
            // $NON-NLS-1$
            out.link(linkAttributes, rootFile.getName(), Messages.getString("SplittingHtmlDocumentBuilder.Home"));
        }
    }
    out.endBlock();
    tableCellAttributes = new TableCellAttributes();
    // $NON-NLS-1$
    tableCellAttributes.setAlign("right");
    // $NON-NLS-1$
    tableCellAttributes.setCssStyle("width: 20%");
    out.beginBlock(BlockType.TABLE_CELL_NORMAL, tableCellAttributes);
    if (next != null) {
        linkAttributes = new LinkAttributes();
        linkAttributes.setTitle(next.getLabel());
        if (navigationImages) {
            ImageAttributes imageAttributes = new ImageAttributes();
            // $NON-NLS-1$
            imageAttributes.setAlt(Messages.getString("SplittingHtmlDocumentBuilder.Next"));
            out.imageLink(linkAttributes, imageAttributes, next.getSplitTarget(), // $NON-NLS-1$
            computeNavImagePath(Messages.getString("SplittingHtmlDocumentBuilder.Next_Image")));
        } else {
            out.link(linkAttributes, next.getSplitTarget(), // $NON-NLS-1$
            Messages.getString("SplittingHtmlDocumentBuilder.Next"));
        }
    }
    out.endBlock();
    // navigation row
    out.endBlock();
    // navigation title row
    out.beginBlock(BlockType.TABLE_ROW, new Attributes());
    tableCellAttributes = new TableCellAttributes();
    // $NON-NLS-1$
    tableCellAttributes.setAlign("left");
    // $NON-NLS-1$
    tableCellAttributes.setValign("top");
    // $NON-NLS-1$
    tableCellAttributes.setCssStyle("width: 20%");
    out.beginBlock(BlockType.TABLE_CELL_NORMAL, tableCellAttributes);
    if (previous != null) {
        out.characters(previous.getLabel());
    }
    out.endBlock();
    tableCellAttributes = new TableCellAttributes();
    // $NON-NLS-1$
    tableCellAttributes.setAlign("center");
    // $NON-NLS-1$
    tableCellAttributes.setCssStyle("width: 60%");
    out.beginBlock(BlockType.TABLE_CELL_NORMAL, tableCellAttributes);
    out.endBlock();
    tableCellAttributes = new TableCellAttributes();
    // $NON-NLS-1$
    tableCellAttributes.setAlign("right");
    // $NON-NLS-1$
    tableCellAttributes.setValign("top");
    // $NON-NLS-1$
    tableCellAttributes.setCssStyle("width: 20%");
    out.beginBlock(BlockType.TABLE_CELL_NORMAL, tableCellAttributes);
    if (next != null) {
        out.characters(next.getLabel());
    }
    out.endBlock();
    // navigation title row
    out.endBlock();
    // table
    out.endBlock();
    if (header) {
        // $NON-NLS-1$
        out.charactersUnescaped("<hr class=\"navigation-separator\"/>");
    }
}
Also used : LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) ImageAttributes(org.eclipse.mylyn.wikitext.parser.ImageAttributes) LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) TableCellAttributes(org.eclipse.mylyn.wikitext.parser.TableCellAttributes) TableAttributes(org.eclipse.mylyn.wikitext.parser.TableAttributes) TableAttributes(org.eclipse.mylyn.wikitext.parser.TableAttributes) ImageAttributes(org.eclipse.mylyn.wikitext.parser.ImageAttributes) TableCellAttributes(org.eclipse.mylyn.wikitext.parser.TableCellAttributes)

Example 19 with ImageAttributes

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

the class AsciiDocDocumentBuilderTest method testImageLinkWithLinkAttributes.

@Test
public void testImageLinkWithLinkAttributes() {
    builder.beginDocument();
    LinkAttributes linkAttr = new LinkAttributes();
    linkAttr.setTitle("Optional link title");
    ImageAttributes imageAttr = new ImageAttributes();
    imageAttr.setAlt("Alt text");
    imageAttr.setTitle("Optional image title");
    builder.imageLink(linkAttr, imageAttr, "http://example.net/", "/path/to/img.jpg");
    builder.endDocument();
    assertMarkup("link:http://example.net/[image:/path/to/img.jpg[Alt text, title=\"Optional image title\"]]\n\n");
}
Also used : LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) ImageAttributes(org.eclipse.mylyn.wikitext.parser.ImageAttributes) Test(org.junit.Test)

Example 20 with ImageAttributes

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

the class AsciiDocDocumentBuilderTest method testImage.

@Test
public void testImage() {
    builder.beginDocument();
    builder.image(new ImageAttributes(), "/path/to/img.jpg");
    builder.endDocument();
    assertMarkup("image:/path/to/img.jpg[]\n\n");
}
Also used : ImageAttributes(org.eclipse.mylyn.wikitext.parser.ImageAttributes) Test(org.junit.Test)

Aggregations

ImageAttributes (org.eclipse.mylyn.wikitext.parser.ImageAttributes)38 Test (org.junit.Test)17 LinkAttributes (org.eclipse.mylyn.wikitext.parser.LinkAttributes)10 Attributes (org.eclipse.mylyn.wikitext.parser.Attributes)3 ImageLinkEvent (org.eclipse.mylyn.wikitext.parser.builder.event.ImageLinkEvent)3 ImageEvent (org.eclipse.mylyn.wikitext.parser.builder.event.ImageEvent)2 Align (org.eclipse.mylyn.wikitext.parser.ImageAttributes.Align)1 TableAttributes (org.eclipse.mylyn.wikitext.parser.TableAttributes)1 TableCellAttributes (org.eclipse.mylyn.wikitext.parser.TableCellAttributes)1