/*
 * Copyright 2018 The Apache Software Foundation.
 *
 * 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 org.apache.pdfbox.pdmodel.interactive.annotation.handlers;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;

public class PDCaretAppearanceHandler extends PDAbstractAppearanceHandler
{
    private static final Log LOG = LogFactory.getLog(PDCaretAppearanceHandler.class);

    public PDCaretAppearanceHandler(PDAnnotation annotation)
    {
        super(annotation);
    }

    @Override
    public void generateAppearanceStreams()
    {
        generateNormalAppearance();
        generateRolloverAppearance();
        generateDownAppearance();
    }

    @Override
    public void generateNormalAppearance()
    {
        // TODO to be implemented
    }

    @Override
    public void generateRolloverAppearance()
    {
        // TODO to be implemented
    }

    @Override
    public void generateDownAppearance()
    {
        // TODO to be implemented
    }
}

@@ -677,16 +677,44 @@
 dlers;%0A%0A
+import java.io.IOException;%0A
 import o
@@ -827,45 +827,351 @@
 del.
-interactive.annotation.PDAnnotation;%0A
+common.PDRectangle;%0Aimport org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;%0Aimport org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationCaret;%0Aimport org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceContentStream;%0A%0A/**%0A * Handler to generate the caret annotations appearance.%0A *%0A * @author Tilman Hausherr%0A */
 %0Apub
@@ -1665,32 +1665,62 @@
 earance()%0A    %7B%0A
+        float lineWidth = 1f;%0A
         // TODO 
@@ -1713,39 +1713,1815 @@
       //
- 
 TODO 
-to be implemented
+Adobe creates the /RD entry, but it is unclear how it%0A        // gets the (identical) numbers. The numbers from there are then substracted/added from /BBox%0A        // and used in the translation in the matrix and also for the line width.%0A%0A        try%0A        %7B%0A            PDAnnotationCaret annotation = (PDAnnotationCaret) getAnnotation();%0A            try (PDAppearanceContentStream contentStream = getNormalAppearanceAsContentStream())%0A            %7B%0A                contentStream.setStrokingColor(getColor());%0A                contentStream.setLineWidth(lineWidth);%0A                contentStream.setNonStrokingColor(getColor());%0A                %0A                handleOpacity(annotation.getConstantOpacity());%0A%0A                PDRectangle rect = getRectangle();%0A                PDRectangle bbox = new PDRectangle(rect.getWidth(), rect.getHeight());%0A                annotation.getNormalAppearanceStream().setBBox(bbox);%0A%0A                float halfX = rect.getWidth() / 2;%0A                float halfY = rect.getHeight() / 2;%0A                contentStream.moveTo(0, 0);%0A                contentStream.curveTo(halfX, 0,%0A                                      halfX, halfY, %0A                                      halfX, rect.getHeight());%0A                contentStream.curveTo(halfX, halfY, %0A                                      halfX, 0,%0A                                      rect.getWidth(), 0);%0A                // closeAndFillAndStroke() would bring a thicker %22thin top%22 shape.%0A                contentStream.closePath();%0A                contentStream.fill();%0A                contentStream.stroke();%0A                //TODO test whether the stroke() and setLineWidth() calls have any effect at all.%0A            %7D%0A        %7D%0A        catch (IOException e)%0A        %7B%0A            LOG.error(e);%0A        %7D
 %0A    %7D%0A%0A
@@ -3728,9 +3728,8 @@
 %0A    %7D%0A%7D
-%0A

add caret annotation handler