<commit_before>/*
 * Copyright 2016 <NAME>
 *
 * 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.
 */

package afester.javafx.svg;

import javafx.geometry.Point2D;
import javafx.scene.paint.CycleMethod;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.RadialGradient;
import javafx.scene.paint.Stop;

import org.apache.batik.anim.dom.SVGOMAnimatedTransformList;
import org.apache.batik.anim.dom.SVGOMGradientElement;
import org.apache.batik.anim.dom.SVGOMLinearGradientElement;
import org.apache.batik.anim.dom.SVGOMRadialGradientElement;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.w3c.dom.Attr;
import org.w3c.dom.svg.SVGMatrix;
import org.w3c.dom.svg.SVGTransform;
import org.w3c.dom.svg.SVGTransformList;

import java.util.List;


public class GradientFactory {
    private static final Logger logger = LogManager.getLogger();

    private GradientPolicy gradientTransformPolicy = GradientPolicy.USE_SUPPORTED;

    /**
     * Creates a new GradientFactory.
     * The gradient transformation policy of the GradientFactory is set to 
     * GradientPolicy.USE_SUPPORTED.
     */
    public GradientFactory() {
    }


    /**
     * Sets the gradient transformation policy of the factory.
     * Valid values are:
     * <ul><li>GradientPolicy.USE_SUPPORTED - The coordinates
     *         for the gradient are transformed using only supported transformation
     *         elements (translation and rotation). This will lead to non-accurate
     *         rendering if the matrix contains skew and/or scaling.</li>
     *     <li>GradientPolicy.USE_AS_IS - The coordinates
     *         for the gradient are transformed using the complete transformation matrix.
     *         This will lead to non-accurate rendering if the matrix contains skew and/or 
     *         scaling.</li>
     *     <li>GradientPolicy.DISCARD - The coordinates are not
     *         transformed at all. This will lead to non-accurate rendering
     *         if the matrix is not the identity matrix.</li></ul>
     * 
     * @param policy The policy to use when gradient transformations are performed.
     */
    public void setTransformationPolicy(GradientPolicy policy) {
        this.gradientTransformPolicy = policy;
    }


    /**
     * Creates a JavaFX LinearGradient from an SVG linearGradient element.
     * Since JavaFX does not yet support gradient transformations, some fuzziness
     * is applied when the SVG gradient definition contains a gradient transformation
     * matrix. The fuzziness can be controlled through the GradientFactory's 
     * gradientTransformPolicy. See {@link #setTransformationPolicy(GradientPolicy)}
     * for more information.
     *
     * @param element The SVG gradient element.
     * @param stops The stops which have already been extracted from the SVG gradient child nodes.
     *
     * @return A JavaFX LinearGradient based on the SVG linear gradient element.
     */
    public LinearGradient createLinearGradient(SVGOMLinearGradientElement element, 
                                               List<Stop> stops) {
        double startX = element.getX1().getBaseVal().getValue();
        double startY = element.getY1().getBaseVal().getValue();
        double endX = element.getX2().getBaseVal().getValue();
        double endY = element.getY2().getBaseVal().getValue();

        /*
ATTENTION:
A gradientTransform in SVG does not transform the gradient parameter coordinates.
Instead, the gradient is generated and then the generated gradient is transformed.
These are two different things!
In case of a LinearGradient, assumed a gradient definition line with an angle of 45,
if the line coordinates are scaled horizontally, this would change the angle.
If the generated gradient image is scaled horizontally, this would not change the angle
(or at least in a different matter). Also, since the gradient flows in a 90
angle regarding the gradient vector, a skew transformation would never be possible
by just transforming start and end coordinates of the gradient.
         */

        SVGMatrix matrix = getGradientTransform(element);
        if (matrix != null) {
            switch (gradientTransformPolicy) {
              case DISCARD :
                  logger.warn("Discarding gradientTransform");
                  break;
<commit_msg>Fixed javadoc error caused by unmappable character<commit_after>/*
 * Copyright 2016 <NAME>
 *
 * 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.
 */

package afester.javafx.svg;

import javafx.geometry.Point2D;
import javafx.scene.paint.CycleMethod;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.RadialGradient;
import javafx.scene.paint.Stop;

import org.apache.batik.anim.dom.SVGOMAnimatedTransformList;
import org.apache.batik.anim.dom.SVGOMGradientElement;
import org.apache.batik.anim.dom.SVGOMLinearGradientElement;
import org.apache.batik.anim.dom.SVGOMRadialGradientElement;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.w3c.dom.Attr;
import org.w3c.dom.svg.SVGMatrix;
import org.w3c.dom.svg.SVGTransform;
import org.w3c.dom.svg.SVGTransformList;

import java.util.List;


public class GradientFactory {
    private static final Logger logger = LogManager.getLogger();

    private GradientPolicy gradientTransformPolicy = GradientPolicy.USE_SUPPORTED;

    /**
     * Creates a new GradientFactory.
     * The gradient transformation policy of the GradientFactory is set to 
     * GradientPolicy.USE_SUPPORTED.
     */
    public GradientFactory() {
    }


    /**
     * Sets the gradient transformation policy of the factory.
     * Valid values are:
     * <ul><li>GradientPolicy.USE_SUPPORTED - The coordinates
     *         for the gradient are transformed using only supported transformation
     *         elements (translation and rotation). This will lead to non-accurate
     *         rendering if the matrix contains skew and/or scaling.</li>
     *     <li>GradientPolicy.USE_AS_IS - The coordinates
     *         for the gradient are transformed using the complete transformation matrix.
     *         This will lead to non-accurate rendering if the matrix contains skew and/or 
     *         scaling.</li>
     *     <li>GradientPolicy.DISCARD - The coordinates are not
     *         transformed at all. This will lead to non-accurate rendering
     *         if the matrix is not the identity matrix.</li></ul>
     * 
     * @param policy The policy to use when gradient transformations are performed.
     */
    public void setTransformationPolicy(GradientPolicy policy) {
        this.gradientTransformPolicy = policy;
    }


    /**
     * Creates a JavaFX LinearGradient from an SVG linearGradient element.
     * Since JavaFX does not yet support gradient transformations, some fuzziness
     * is applied when the SVG gradient definition contains a gradient transformation
     * matrix. The fuzziness can be controlled through the GradientFactory's 
     * gradientTransformPolicy. See {@link #setTransformationPolicy(GradientPolicy)}
     * for more information.
     *
     * @param element The SVG gradient element.
     * @param stops The stops which have already been extracted from the SVG gradient child nodes.
     *
     * @return A JavaFX LinearGradient based on the SVG linear gradient element.
     */
    public LinearGradient createLinearGradient(SVGOMLinearGradientElement element, 
                                               List<Stop> stops) {
        double startX = element.getX1().getBaseVal().getValue();
        double startY = element.getY1().getBaseVal().getValue();
        double endX = element.getX2().getBaseVal().getValue();
        double endY = element.getY2().getBaseVal().getValue();

        /*
ATTENTION:
A gradientTransform in SVG does not transform the gradient parameter coordinates.
Instead, the gradient is generated and then the generated gradient is transformed.
These are two different things!
In case of a LinearGradient, assumed a gradient definition line with an angle of 45deg,
if the line coordinates are scaled horizontally, this would change the angle.
If the generated gradient image is scaled horizontally, this would not change the angle
(or at least in a different matter). Also, since the gradient flows in a 90deg
angle regarding the gradient vector, a skew transformation would never be possible
by just transforming start and end coordinates of the gradient.
         */

        SVGMatrix matrix = getGradientTransform(element);
        if (matrix != null) {
            switch (gradientTransformPolicy) {
              case DISCARD :
                  logger.warn("Discarding gradientTransform");
                  break;

{'fraction_non_alphanumeric': 0.07004608294930875, 'fraction_numerical': 0.004710701484895033, 'mean_word_length': 3.171721486544212, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2768528', 'n_tokens_mistral': 2552, 'n_tokens_neox': 2420, 'n_words': 940}