<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>FDFAnnotationCaret.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Apache PDFBox</a> &gt; <a href="index.source.html" class="el_package">org.apache.pdfbox.pdmodel.fdf</a> &gt; <span class="el_source">FDFAnnotationCaret.java</span></div><h1>FDFAnnotationCaret.java</h1><pre class="source lang-java linenums">/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the &quot;License&quot;); 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 &quot;AS IS&quot; 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 org.apache.pdfbox.pdmodel.fdf;

import java.io.IOException;

import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.w3c.dom.Element;

/**
 * This represents a Caret FDF annotation.
 *
 * @author Ben Litchfield
 */
public class FDFAnnotationCaret extends FDFAnnotation
{
    /**
     * COS Model value for SubType entry.
     */
    public static final String SUBTYPE = &quot;Caret&quot;;

    /**
     * Default constructor.
     */
    public FDFAnnotationCaret()
    {
<span class="nc" id="L44">        super();</span>
<span class="nc" id="L45">        annot.setName(COSName.SUBTYPE, SUBTYPE);</span>
<span class="nc" id="L46">    }</span>

    /**
     * Constructor.
     *
     * @param a An existing FDF Annotation.
     */
    public FDFAnnotationCaret(COSDictionary a)
    {
<span class="nc" id="L55">        super(a);</span>
<span class="nc" id="L56">    }</span>

    /**
     * Constructor.
     *
     * @param element An XFDF element.
     *
     * @throws IOException If there is an error extracting information from the element.
     */
    public FDFAnnotationCaret(Element element) throws IOException
    {
<span class="nc" id="L67">        super(element);</span>
<span class="nc" id="L68">        annot.setName(COSName.SUBTYPE, SUBTYPE);</span>

<span class="nc" id="L70">        initFringe(element);</span>

<span class="nc" id="L72">        String symbol = element.getAttribute(&quot;symbol&quot;);</span>
<span class="nc bnc" id="L73" title="All 4 branches missed.">        if (symbol != null &amp;&amp; !symbol.isEmpty())</span>
        {
<span class="nc" id="L75">            setSymbol(symbol);</span>
        }
<span class="nc" id="L77">    }</span>

    private void initFringe(Element element) throws IOException
    {
<span class="nc" id="L81">        String fringe = element.getAttribute(&quot;fringe&quot;);</span>
<span class="nc bnc" id="L82" title="All 4 branches missed.">        if (fringe != null &amp;&amp; !fringe.isEmpty())</span>
        {
<span class="nc" id="L84">            String[] fringeValues = fringe.split(&quot;,&quot;);</span>
<span class="nc bnc" id="L85" title="All 2 branches missed.">            if (fringeValues.length != 4)</span>
            {
<span class="nc" id="L87">                throw new IOException(&quot;Error: wrong amount of numbers in attribute 'fringe'&quot;);</span>
            }
<span class="nc" id="L89">            PDRectangle rect = new PDRectangle();</span>
<span class="nc" id="L90">            rect.setLowerLeftX(Float.parseFloat(fringeValues[0]));</span>
<span class="nc" id="L91">            rect.setLowerLeftY(Float.parseFloat(fringeValues[1]));</span>
<span class="nc" id="L92">            rect.setUpperRightX(Float.parseFloat(fringeValues[2]));</span>
<span class="nc" id="L93">            rect.setUpperRightY(Float.parseFloat(fringeValues[3]));</span>
<span class="nc" id="L94">            setFringe(rect);</span>
        }
<span class="nc" id="L96">    }</span>

    /**
     * This will set the fringe rectangle. Giving the difference between the annotations rectangle and where the drawing
     * occurs.
     *
     * @param fringe the fringe
     */
    public final void setFringe(PDRectangle fringe)
    {
<span class="nc" id="L106">        annot.setItem(COSName.RD, fringe);</span>
<span class="nc" id="L107">    }</span>

    /**
     * This will retrieve the fringe. Giving the difference between the annotations rectangle and where the drawing
     * occurs.
     *
     * @return the rectangle difference
     */
    public PDRectangle getFringe()
    {
<span class="nc" id="L117">        COSArray rd = annot.getCOSArray(COSName.RD);</span>
<span class="nc bnc" id="L118" title="All 2 branches missed.">        return rd != null ? new PDRectangle(rd) : null;</span>
    }

    /**
     * This will set the symbol that shall be associated with the caret.
     * 
     * @param symbol the symbol
     */
    public final void setSymbol(String symbol)
    {
<span class="nc" id="L128">        String newSymbol = &quot;None&quot;;</span>
<span class="nc bnc" id="L129" title="All 2 branches missed.">        if (&quot;paragraph&quot;.equals(symbol))</span>
        {
<span class="nc" id="L131">            newSymbol = &quot;P&quot;;</span>
        }
<span class="nc" id="L133">        annot.setString(COSName.SY, newSymbol);</span>
<span class="nc" id="L134">    }</span>

    /**
     * This will retrieve the symbol that shall be associated with the caret.
     * 
     * @return the symbol
     */
    public String getSymbol()
    {
<span class="nc" id="L143">        return annot.getString(COSName.SY);</span>
    }
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.8.202204050719</span></div></body></html>