All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.xhtmlrenderer.util.FontUtil Maven / Gradle / Ivy

Go to download

Flying Saucer is a CSS 2.1 renderer written in Java. This artifact contains the core rendering and layout code as well as Java2D output.

There is a newer version: 9.9.3
Show newest version
package org.xhtmlrenderer.util;

import javax.xml.bind.DatatypeConverter;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.logging.Level;

public class FontUtil {

    public static Boolean isEmbeddedBase64Font(String uri) {
        return uri != null && uri.startsWith("data:font/");
    }

    public static InputStream getEmbeddedBase64Data(String uri) {
        int b64Index = (uri!= null)? uri.indexOf("base64,") : -1;
        if (b64Index != -1) {
            String b64encoded = uri.substring(b64Index + "base64,".length());
            return new ByteArrayInputStream(DatatypeConverter.parseBase64Binary(b64encoded));
        } else {
            XRLog.load(Level.SEVERE, "Embedded css fonts must be encoded in base 64.");
            return null;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy