Skip to content

Commit 345a64f

Browse files
committed
Add DeviceRGB constructor that takes system's color
DEVSIX-1358
1 parent d9ea18d commit 345a64f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

io/src/main/java/com/itextpdf/io/LogMessageConstant.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public final class LogMessageConstant {
5353
public static final String ATTEMPT_TO_MOVE_TO_FLUSHED_PARENT = "An attempt is made to move the tag tree pointer to the tag parent which has been already flushed. Tag tree pointer is moved to the root tag instead.";
5454
public static final String CALCULATE_HASHCODE_FOR_MODIFIED_PDFNUMBER = "Calculate hashcode for modified PdfNumber.";
5555
public static final String CLIP_ELEMENT = "Element content was clipped because some height properties are set.";
56+
public static final String COLOR_ALPHA_CHANNEL_IS_IGNORED = "Alpha channel {0} was ignored during creation of color";
5657
public static final String COLORANT_INTENSITIES_INVALID = "Some of colorant intensities are invalid: they are bigger than 1 or less than 0. We will force them to become 1 or 0 respectively.";
5758
public static final String COLOR_NOT_FOUND = "Color \"{0}\" not found.";
5859
public static final String COLOR_NOT_PARSED = "Color \"{0}\" was not parsed. It has invalid value. Defaulting to black color.";

kernel/src/main/java/com/itextpdf/kernel/color/DeviceRgb.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ This file is part of the iText (R) project.
4444
package com.itextpdf.kernel.color;
4545

4646
import com.itextpdf.io.LogMessageConstant;
47+
import com.itextpdf.io.util.MessageFormatUtil;
4748
import com.itextpdf.kernel.pdf.colorspace.PdfDeviceCs;
4849
import org.slf4j.Logger;
4950
import org.slf4j.LoggerFactory;
@@ -115,6 +116,20 @@ public DeviceRgb(float r, float g, float b) {
115116
}
116117
}
117118

119+
/**
120+
* Create DeviceRGB color from R, G, B values of java.awt.Color
121+
* Note, that alpha chanel is ignored
122+
*
123+
* @param color the color which RGB values are used
124+
*/
125+
public DeviceRgb(java.awt.Color color) {
126+
this(color.getRed(), color.getGreen(), color.getBlue());
127+
if (color.getAlpha() != 255) {
128+
Logger LOGGER = LoggerFactory.getLogger(DeviceRgb.class);
129+
LOGGER.warn(MessageFormatUtil.format(LogMessageConstant.COLOR_ALPHA_CHANNEL_IS_IGNORED, color.getAlpha()));
130+
}
131+
}
132+
118133
/**
119134
* Creates DeviceRgb color with all colorants intensities initialised as zeroes.
120135
*/

0 commit comments

Comments
 (0)