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

com.googlecode.blaisemath.graphics.svg.SvgUtils Maven / Gradle / Ivy

package com.googlecode.blaisemath.graphics.svg;

/*-
 * #%L
 * blaise-graphics
 * --
 * Copyright (C) 2009 - 2024 Elisha Peterson
 * --
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import com.google.common.annotations.Beta;
import com.googlecode.blaisemath.graphics.swing.JGraphicComponent;
import com.googlecode.blaisemath.util.Images;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.awt.Component;
import java.awt.Container;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Base64;
import java.util.Objects;
import static java.util.Objects.requireNonNull;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;

/**
 * Utilities for working with SVG.
 * 
 * @author Elisha Peterson
 */
@Beta
public class SvgUtils {

    private static final Logger LOG = Logger.getLogger(SvgUtils.class.getName());
    private static final String GET_GRAPHIC_COMPONENT_METHOD = "getGraphicComponent";
    
    /** Identifier for svg (raw) */
    public static final String FORMAT_SVG_RAW = "svg+raw";
    /** Identifier for svg (base64 encoded) */
    public static final String FORMAT_SVG_BASE64 = "svg";
    
    /** String produced when unable to export SVG */
    public static final String UNSUPPORTED_SVG = "