Skip to content

Commit

Permalink
Added possibility insert BASE64-encoded images.
Browse files Browse the repository at this point in the history
For example, <img
src="data:image/png;base64,iVBORw0KGgoAAAANS......BJRU5ErkJggg==" />
  • Loading branch information
bvfalcon committed Apr 14, 2019
1 parent f2bda4a commit 56f8dc0
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.security.AccessControlException;
import java.util.logging.Level;

import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import javax.swing.plaf.basic.BasicHTML;
import javax.swing.text.View;
import javax.swing.text.html.HTMLDocument;

import org.apache.commons.lang.StringUtils;
import org.freeplane.core.resources.ResourceController;
import org.freeplane.core.util.HtmlUtils;
import org.freeplane.core.util.LogUtils;
Expand Down Expand Up @@ -129,7 +134,17 @@ private void updateTextUnsafe(String nodeText) throws Exception{
isLong = widthMustBeRestricted || lines.length > 1;
}
if (isHtml) {
if (nodeText.indexOf("<img") >= 0 && nodeText.indexOf("<base ") < 0) {
if (nodeText.indexOf("<img") >= 0 && nodeText.indexOf("src=\"data:") >= 0) {
String base64String = StringUtils.substringBetween(nodeText, "base64,", "\"");
LogUtils.getLogger().log(Level.FINE, "base64String = " + base64String);
byte[] imageByte = org.apache.commons.codec.binary.Base64.decodeBase64(base64String);
ByteArrayInputStream inputStream = new ByteArrayInputStream(imageByte);
BufferedImage bufImage = ImageIO.read(inputStream);
ImageIcon icon = new ImageIcon(bufImage);
setIcon(icon);
return;
}
else if (nodeText.indexOf("<img") >= 0 && nodeText.indexOf("<base ") < 0) {
nodeText = "<html><base href=\"" + map.getModel().getURL() + "\">" + nodeText.substring(6);
}
final String htmlLongNodeHead = ResourceController.getResourceController().getProperty(
Expand Down

0 comments on commit 56f8dc0

Please sign in to comment.