use of com.vladsch.flexmark.html.renderer.ResolvedLink in project flexmark-java by vsch.
the class CoreNodeDocxRenderer method render.
private void render(final Emoji node, final DocxRendererContext docx) {
final EmojiResolvedShortcut shortcut = EmojiResolvedShortcut.getEmojiText(node, emojiOptions.useShortcutType, emojiOptions.useImageType, emojiOptions.rootImagePath);
if (shortcut.emoji == null || shortcut.emojiText == null) {
// output as text
docx.text(":");
docx.renderChildren(node);
docx.text(":");
} else {
if (shortcut.isUnicode) {
docx.text(shortcut.emojiText);
} else {
ResolvedLink resolvedLink = docx.resolveLink(LinkType.IMAGE, shortcut.emojiText, null, null);
String altText = shortcut.alt;
String url = resolvedLink.getUrl();
Attributes attributes = resolvedLink.getNonNullAttributes();
if (shortcut.alt != null) {
attributes.replaceValue("alt", shortcut.alt);
}
// need to determine the font point size from the style
RPr rPr = docx.getFactory().createRPr();
RPr paraRPr = docx.getFactory().createRPr();
PPr pPr = docx.getFactory().createPPr();
docx.getBlockFormatProvider().getPPr(pPr);
docx.getBlockFormatProvider().getParaRPr(paraRPr);
paraRPr = docx.getHelper().getExplicitRPr(paraRPr, pPr);
docx.getRunFormatProvider().getRPr(rPr);
rPr = docx.getHelper().getExplicitRPr(rPr);
StyleUtil.apply(rPr, paraRPr);
StyleUtil.apply(paraRPr, rPr);
// now see if we have line height
final HpsMeasure sz = rPr.getSz();
long l = -1;
if (sz != null) {
l = sz.getVal().longValue();
attributes.replaceValue("height", String.valueOf(Math.round(l / 2 / options.docEmojiImageVertSize)));
attributes.replaceValue("width", String.valueOf(Math.round(l / 2 / options.docEmojiImageVertSize)));
} else if (!emojiOptions.attrImageSize.isEmpty()) {
attributes.replaceValue("height", emojiOptions.attrImageSize);
attributes.replaceValue("width", emojiOptions.attrImageSize);
// page dimensions not used, these are not %
l = getSizeInfo(attributes, "width", 100.0);
// now revert from twips to points
l /= 20;
}
if (!emojiOptions.attrAlign.isEmpty()) {
attributes.replaceValue("align", emojiOptions.attrAlign);
}
attributes = docx.extendRenderingNodeAttributes(AttributablePart.NODE, attributes);
R r = renderImage(docx, url, attributes);
// <w:position w:val="-4"/>
if (r != null) {
long adj = Math.round(l * options.docEmojiImageVertOffset);
if (adj < 0) {
RPr rPr1 = r.getRPr();
if (rPr1 == null) {
rPr1 = docx.getFactory().createRPr();
r.setRPr(rPr1);
}
CTSignedHpsMeasure hpsMeasure = docx.getFactory().createCTSignedHpsMeasure();
rPr1.setPosition(hpsMeasure);
hpsMeasure.setVal(BigInteger.valueOf(adj));
}
}
}
}
}
Aggregations