Alpha value of fill color take no effect after PdfContentByte.restoreState() call.
Describe the bug After restoreState(), set alpha value of fill color not working , if alpha value of the new fill color equals alpha value of the last fill color.
OpenPDF version 1.3.26
To Reproduce Run this test application.
import com.lowagie.text.Document;
import com.lowagie.text.PageSize;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
import java.awt.*;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class Test {
public static void main(String[] args) throws IOException {
try (BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream("/tmp/output.pdf"))) {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, outputStream);
document.open();
PdfContentByte cb = writer.getDirectContent();
document.setPageSize(PageSize.A4);
document.newPage();
//draw first rectangle
cb.saveState();
cb.setColorFill(new Color(255, 0, 0, 50)); //alpha value = 50
cb.setColorStroke(Color.RED);
cb.rectangle(200, 400, 30, 30);
cb.fillStroke();
cb.restoreState();
//draw second rectangle
cb.saveState();
cb.setColorFill(new Color(0, 0, 255, 50)); //same alpha value (50)
cb.setColorStroke(Color.BLUE);
cb.rectangle(300, 400, 30, 30);
cb.fillStroke();
cb.restoreState();
document.close();
}
}
}
Expected output

Output

Indeed, saveState and restoreState have not been considered in the last*Alpha handling. strictly speaking those should not have been made PdfContentByte members; instead the graphics state should have been used.
Hi, I'd like to work on this issue for a school project. Thanks!
Pull requests are welcome.
Hi,can I get a pull request? Is this issue still open, I want to work on this to solve the issue
HI @YourLord00 , fell free in creating a pull request. The issue still open.
Thank you, I will just create pull request, so would this be like the normal clone git repo?
On Thu, Nov 4, 2021 at 6:09 AM asturio @.***> wrote:
HI @YourLord00 https://github.com/YourLord00 , fell free in creating a pull request. The issue still open.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/LibrePDF/OpenPDF/issues/589#issuecomment-960615703, or unsubscribe https://github.com/notifications/unsubscribe-auth/AR7VSME7WKBPRX2VBIGZLZ3UKJLU3ANCNFSM5CN6AGTA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
Thank you, I will just create pull request, so would this be like the normal way to clone git repo?
On Thu, Nov 4, 2021 at 9:12 AM Jiachun Tang @.***> wrote:
Thank you, I will just create pull request, so would this be like the normal clone git repo?
On Thu, Nov 4, 2021 at 6:09 AM asturio @.***> wrote:
HI @YourLord00 https://github.com/YourLord00 , fell free in creating a pull request. The issue still open.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/LibrePDF/OpenPDF/issues/589#issuecomment-960615703, or unsubscribe https://github.com/notifications/unsubscribe-auth/AR7VSME7WKBPRX2VBIGZLZ3UKJLU3ANCNFSM5CN6AGTA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.