• R/O
  • SSH
  • HTTPS

copper: Commit


Commit MetaInfo

Revision1626 (tree)
Time2022-05-03 09:35:38
Authormiyabe

Log Message

(empty log message)

Change Summary

Incremental Difference

--- copper/trunk/homare/src/main/java/jp/cssj/homare/css/util/ColorValueUtils.java (revision 1625)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/css/util/ColorValueUtils.java (revision 1626)
@@ -8,8 +8,11 @@
88 import jp.cssj.homare.css.value.BackgroundAttachmentValue;
99 import jp.cssj.homare.css.value.BackgroundRepeatValue;
1010 import jp.cssj.homare.css.value.ColorValue;
11+import jp.cssj.homare.css.value.PaintValue;
12+import jp.cssj.homare.css.value.css3.LinearGradientValue;
1113 import jp.cssj.homare.ua.UserAgent;
1214 import jp.cssj.sakae.gc.paint.CMYKColor;
15+import jp.cssj.sakae.gc.paint.Color;
1316 import jp.cssj.sakae.gc.paint.GrayColor;
1417 import jp.cssj.sakae.gc.paint.RGBAColor;
1518 import jp.cssj.sakae.gc.paint.RGBColor;
@@ -35,7 +38,7 @@
3538 /**
3639 * The 'black' RGB color.
3740 */
38- public static final ColorValue BLACK = fromGrayValue(0);
41+ public static final ColorValue BLACK = fromGrayComponent(0);
3942
4043 /**
4144 * The 'blue' RGB color.
@@ -55,7 +58,7 @@
5558 /**
5659 * The 'gray' RGB color.
5760 */
58- public static final ColorValue GRAY = fromGrayValue(0.5f);
61+ public static final ColorValue GRAY = fromGrayComponent(0.5f);
5962
6063 /**
6164 * The 'lime' RGB color.
@@ -90,7 +93,7 @@
9093 /**
9194 * The 'silver' RGB color.
9295 */
93- public static final ColorValue SILVER = fromGrayValue(192f / 255f);
96+ public static final ColorValue SILVER = fromGrayComponent(192f / 255f);
9497
9598 /**
9699 * The 'teal' RGB color.
@@ -100,7 +103,7 @@
100103 /**
101104 * The 'white' RGB color.
102105 */
103- public static final ColorValue WHITE = fromGrayValue(255f);
106+ public static final ColorValue WHITE = fromGrayComponent(255f);
104107
105108 /**
106109 * The 'yellow' RGB color.
@@ -216,7 +219,7 @@
216219 /**
217220 * The 'darkgray' RGB color.
218221 */
219- public static final ColorValue DARKGRAY = fromGrayValue(169f / 255f);
222+ public static final ColorValue DARKGRAY = fromGrayComponent(169f / 255f);
220223
221224 /**
222225 * The 'darkgreen' RGB color.
@@ -306,7 +309,7 @@
306309 /**
307310 * The 'dimgray' RGB color.
308311 */
309- public static final ColorValue DIMGRAY = fromGrayValue(105f / 255f);
312+ public static final ColorValue DIMGRAY = fromGrayComponent(105f / 255f);
310313
311314 /**
312315 * The 'dimgrey' RGB color.
@@ -436,7 +439,7 @@
436439 /**
437440 * The 'lightgray' RGB color.
438441 */
439- public static final ColorValue LIGHTGRAY = fromGrayValue(211f / 255f);
442+ public static final ColorValue LIGHTGRAY = fromGrayComponent(211f / 255f);
440443
441444 /**
442445 * The 'lightgreen' RGB color.
@@ -1001,7 +1004,7 @@
10011004 map.put("window", WINDOW);
10021005 map.put("windowframe", WINDOWFRAME);
10031006 map.put("windowtext", WINDOWTEXT);
1004-
1007+
10051008 map.put("transparent", TRANSPARENT);
10061009
10071010 COLORNAME_TO_CSS_COLOR = Collections.unmodifiableMap(map);
@@ -1015,16 +1018,29 @@
10151018 return (ColorValue) COLORNAME_TO_CSS_COLOR.get(colorName.toLowerCase());
10161019 }
10171020
1018- public static ColorValue fromRGBOctets(int red, int green, int blue) {
1019- return new ColorValue(RGBColor.create((float) red / 255f, (float) green / 255f, (float) blue / 255f));
1021+ private static ColorValue fromRGBOctets(int red, int green, int blue) {
1022+ return new ColorValue(RGBColor.create((float) red / 255f, (float) green / 255f, (float) blue / 255f));
10201023 }
10211024
1022- public static ColorValue fromCMYKOctets(int cyan, int yellow, int magenta, int black) {
1023- return new ColorValue(CMYKColor.create((float) cyan / 255f, (float) yellow / 255f, (float) magenta / 255f,
1024- (float) black / 255f));
1025+ private static ColorValue fromRGBComponents(float red, float green, float blue) {
1026+ if (red == 0 && green == 0 && blue == 0) {
1027+ return BLACK;
1028+ }
1029+ if (red == 1f && green == 1f && blue == 1f) {
1030+ return WHITE;
1031+ }
1032+ return new ColorValue(RGBColor.create(red, green, blue));
10251033 }
10261034
1027- public static ColorValue fromGrayValue(float g) {
1035+ private static ColorValue fromRGBAComponents(float red, float green, float blue, float alpha) {
1036+ return new ColorValue(RGBAColor.create(red, green, blue, alpha));
1037+ }
1038+
1039+ private static ColorValue fromCMYKComponents(float cyan, float magenta, float yellow, float black, byte overprint) {
1040+ return new ColorValue(CMYKColor.create(cyan, magenta, yellow, black, overprint));
1041+ }
1042+
1043+ private static ColorValue fromGrayComponent(float g) {
10281044 return new ColorValue(GrayColor.create(g));
10291045 }
10301046
@@ -1066,7 +1082,7 @@
10661082 value = value.getNextLexicalUnit().getNextLexicalUnit();
10671083 float blue = toColorComponent(value);
10681084
1069- return new ColorValue(RGBColor.create(red, green, blue));
1085+ return fromRGBComponents(red, green, blue);
10701086 } catch (IllegalArgumentException e) {
10711087 return null;
10721088 }
@@ -1078,7 +1094,7 @@
10781094 * @param value
10791095 * @return
10801096 */
1081- private static ColorValue toRGBAColorValue(LexicalUnit value) {
1097+ private static ColorValue toRGBAColorValue(LexicalUnit value) {
10821098 try {
10831099 float red = toColorComponent(value);
10841100
@@ -1091,7 +1107,7 @@
10911107 value = value.getNextLexicalUnit().getNextLexicalUnit();
10921108 float alpha = toColorComponent(value);
10931109
1094- return new ColorValue(RGBAColor.create(red, green, blue, alpha));
1110+ return fromRGBAComponents(red, green, blue, alpha);
10951111 } catch (IllegalArgumentException e) {
10961112 return null;
10971113 }
@@ -1130,15 +1146,28 @@
11301146 }
11311147 }
11321148
1133- return new ColorValue(CMYKColor.create(cyan, magenta, yellow, black, overprint));
1149+ return fromCMYKComponents(cyan, magenta, yellow, black, overprint);
11341150 } catch (IllegalArgumentException e) {
11351151 return null;
11361152 }
11371153 }
11381154
1155+ private static PaintValue toLinearGradient(UserAgent ua, LexicalUnit lu) {
1156+ try {
1157+ ColorValue color1 = toColor(ua, lu);
1158+ lu = lu.getNextLexicalUnit().getNextLexicalUnit();
1159+ ColorValue color2 = toColor(ua, lu);
1160+
1161+ return new LinearGradientValue(new double[] { 0, 1 },
1162+ new Color[] { color1.getColor(), color2.getColor() });
1163+ } catch (IllegalArgumentException e) {
1164+ return null;
1165+ }
1166+ }
1167+
11391168 private static ColorValue toGrayColorValue(LexicalUnit value) {
11401169 try {
1141- return fromGrayValue(toColorComponent(value));
1170+ return fromGrayComponent(toColorComponent(value));
11421171 } catch (IllegalArgumentException e) {
11431172 return null;
11441173 }
@@ -1211,6 +1240,29 @@
12111240 }
12121241
12131242 /**
1243+ * <background-color> を値に変換します。
1244+ *
1245+ * @param lu
1246+ * @return
1247+ */
1248+ public static PaintValue toPaint(UserAgent ua, LexicalUnit lu) {
1249+ PaintValue value = toColor(ua, lu);
1250+ if (value != null) {
1251+ return value;
1252+ }
1253+ switch (lu.getLexicalUnitType()) {
1254+ case LexicalUnit.SAC_FUNCTION:
1255+ String func = lu.getFunctionName();
1256+ if (func.equalsIgnoreCase("linear-gradient")) {
1257+ LexicalUnit lg = lu.getParameters();
1258+ return toLinearGradient(ua, lg);
1259+ }
1260+ break;
1261+ }
1262+ return null;
1263+ }
1264+
1265+ /**
12141266 * <background-repeat> を値に変換します。
12151267 *
12161268 * @param lu
--- copper/trunk/homare/src/main/java/jp/cssj/homare/css/value/ColorValue.java (revision 1625)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/css/value/ColorValue.java (revision 1626)
@@ -1,12 +1,15 @@
11 package jp.cssj.homare.css.value;
22
3+import java.awt.geom.Rectangle2D;
4+
35 import jp.cssj.sakae.gc.paint.Color;
6+import jp.cssj.sakae.gc.paint.Paint;
47
58 /**
69 * @author MIYABE Tatsuhiko
710 * @version $Id$
811 */
9-public class ColorValue implements Value {
12+public class ColorValue implements PaintValue {
1013 protected final Color color;
1114
1215 public ColorValue(Color color) {
@@ -13,11 +16,15 @@
1316 this.color = color;
1417 }
1518
19+ public Paint getPaint(Rectangle2D box) {
20+ return this.color;
21+ }
22+
1623 public Color getColor() {
1724 return this.color;
1825 }
1926
20- public short getValueType() {
27+ public final short getValueType() {
2128 return Value.TYPE_COLOR;
2229 }
2330
@@ -25,8 +32,8 @@
2532 if (o instanceof ColorValue) {
2633 return ((ColorValue)o).getColor().equals(this.color);
2734 }
28- if (o instanceof Color) {
29- return ((Color)o).equals(this.color);
35+ if (o instanceof Paint) {
36+ return ((Paint)o).equals(this.color);
3037 }
3138 return false;
3239 }
--- copper/trunk/homare/src/main/java/jp/cssj/homare/css/value/PaintValue.java (revision 1625)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/css/value/PaintValue.java (revision 1626)
@@ -1,5 +1,7 @@
11 package jp.cssj.homare.css.value;
22
3+import java.awt.geom.Rectangle2D;
4+
35 import jp.cssj.sakae.gc.paint.Paint;
46
57 /**
@@ -6,18 +8,6 @@
68 * @author MIYABE Tatsuhiko
79 * @version $Id: ColorValue.java 1552 2018-04-26 01:43:24Z miyabe $
810 */
9-public class PaintValue implements Value {
10- protected final Paint paint;
11-
12- public PaintValue(Paint paint) {
13- this.paint = paint;
14- }
15-
16- public Paint getPaint() {
17- return this.paint;
18- }
19-
20- public short getValueType() {
21- return Value.TYPE_COLOR;
22- }
11+public interface PaintValue extends Value {
12+ public Paint getPaint(Rectangle2D box);
2313 }
\ No newline at end of file
--- copper/trunk/homare/src/main/java/jp/cssj/homare/css/value/css3/LinearGradientValue.java (nonexistent)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/css/value/css3/LinearGradientValue.java (revision 1626)
@@ -0,0 +1,32 @@
1+package jp.cssj.homare.css.value.css3;
2+
3+import java.awt.geom.AffineTransform;
4+import java.awt.geom.Rectangle2D;
5+
6+import jp.cssj.homare.css.value.PaintValue;
7+import jp.cssj.homare.css.value.Value;
8+import jp.cssj.sakae.gc.paint.Color;
9+import jp.cssj.sakae.gc.paint.LinearGradient;
10+import jp.cssj.sakae.gc.paint.Paint;
11+
12+/**
13+ * @author MIYABE Tatsuhiko
14+ * @version $Id: ColorValue.java 1624 2022-05-02 08:59:55Z miyabe $
15+ */
16+public class LinearGradientValue implements PaintValue {
17+ protected final Color[] colors;
18+ protected final double[] fractions;
19+
20+ public LinearGradientValue(double[] fractions, Color[] colors) {
21+ this.colors = colors;
22+ this.fractions = fractions;
23+ }
24+
25+ public Paint getPaint(Rectangle2D box) {
26+ return new LinearGradient(0, box.getMinY(), 0, box.getMaxY(), this.fractions, this.colors, new AffineTransform());
27+ }
28+
29+ public short getValueType() {
30+ return Value.TYPE_COLOR;
31+ }
32+}
\ No newline at end of file
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- copper/trunk/homare/src/main/java/jp/cssj/homare/impl/css/property/BackgroundColor.java (revision 1625)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/impl/css/property/BackgroundColor.java (revision 1626)
@@ -7,11 +7,10 @@
77 import jp.cssj.homare.css.property.PrimitivePropertyInfo;
88 import jp.cssj.homare.css.property.PropertyException;
99 import jp.cssj.homare.css.util.ColorValueUtils;
10-import jp.cssj.homare.css.value.ColorValue;
10+import jp.cssj.homare.css.value.PaintValue;
1111 import jp.cssj.homare.css.value.TransparentValue;
1212 import jp.cssj.homare.css.value.Value;
1313 import jp.cssj.homare.ua.UserAgent;
14-import jp.cssj.sakae.gc.paint.Color;
1514 import jp.cssj.sakae.sac.css.LexicalUnit;
1615
1716 /**
@@ -21,12 +20,12 @@
2120 public class BackgroundColor extends AbstractPrimitivePropertyInfo {
2221 public static final PrimitivePropertyInfo INFO = new BackgroundColor();
2322
24- public static Color get(CSSStyle style) {
23+ public static PaintValue get(CSSStyle style) {
2524 Value value = style.get(INFO);
2625 if (value.getValueType() == Value.TYPE_TRANSPARENT) {
2726 return null;
2827 }
29- return ((ColorValue) value).getColor();
28+ return (PaintValue)value;
3029 }
3130
3231 protected BackgroundColor() {
@@ -49,7 +48,7 @@
4948 if (ColorValueUtils.isTransparent(lu)) {
5049 return TransparentValue.TRANSPARENT_VALUE;
5150 }
52- Value value = ColorValueUtils.toColor(ua, lu);
51+ Value value = ColorValueUtils.toPaint(ua, lu);
5352 if (value == null) {
5453 throw new PropertyException();
5554 }
--- copper/trunk/homare/src/main/java/jp/cssj/homare/impl/css/property/shorthand/BackgroundShorthand.java (revision 1625)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/impl/css/property/shorthand/BackgroundShorthand.java (revision 1626)
@@ -65,7 +65,7 @@
6565 primitives.set(BackgroundColor.INFO, TransparentValue.TRANSPARENT_VALUE);
6666 continue;
6767 }
68- Value value = ColorValueUtils.toColor(ua, lu);
68+ Value value = ColorValueUtils.toPaint(ua, lu);
6969 if (value != null) {
7070 if (color) {
7171 throw new PropertyException("colorが2度指定されています");
--- copper/trunk/homare/src/main/java/jp/cssj/homare/style/box/AbstractTextBox.java (revision 1625)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/style/box/AbstractTextBox.java (revision 1626)
@@ -7,6 +7,7 @@
77 import java.util.ArrayList;
88 import java.util.List;
99
10+import jp.cssj.homare.css.util.ColorValueUtils;
1011 import jp.cssj.homare.message.MessageCodes;
1112 import jp.cssj.homare.style.box.content.JustificationState;
1213 import jp.cssj.homare.style.box.impl.InlineBlockBox;
@@ -30,6 +31,7 @@
3031 import jp.cssj.sakae.gc.GC;
3132 import jp.cssj.sakae.gc.GraphicsException;
3233 import jp.cssj.sakae.gc.paint.Color;
34+import jp.cssj.sakae.gc.paint.LinearGradient;
3335 import jp.cssj.sakae.gc.paint.RGBColor;
3436 import jp.cssj.sakae.gc.text.GlyphHandler;
3537 import jp.cssj.sakae.gc.text.Text;
@@ -468,9 +470,8 @@
468470
469471 // テキスト本体
470472 gc.begin();
471- Color color = this.params.color;
472- if (color != null) {
473- gc.setFillPaint(color);
473+ if (this.params.color != null) {
474+ gc.setFillPaint(this.params.color);
474475 }
475476 if (this.params.textStrokeWidth != 0) {
476477 gc.setLinePattern(GC.STROKE_SOLID);
--- copper/trunk/homare/src/main/java/jp/cssj/homare/style/box/content/FlowContainer.java (revision 1625)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/style/box/content/FlowContainer.java (revision 1626)
@@ -448,6 +448,35 @@
448448 throw new IllegalStateException();
449449 }
450450 }
451+
452+// public final void textShape(GeneralPath path, double x, double y) {
453+// if (this.flows == null) {
454+// return;
455+// }
456+// switch (this.box.getBlockParams().flow) {
457+// case AbstractTextParams.FLOW_TB:
458+// // 横書き
459+// // 通常のフロー
460+// for (int i = 0; i < this.flows.size(); ++i) {
461+// Flow c = (Flow) this.flows.get(i);
462+// c.box.textShape(path, x, y + c.pageAxis);
463+// }
464+// break;
465+// case AbstractTextParams.FLOW_RL:
466+// case AbstractTextParams.FLOW_LR:
467+// // 縦書き
468+// x += this.box.getInnerWidth();
469+// for (int i = 0; i < this.flows.size(); ++i) {
470+// // 通常のフロー
471+// Flow c = (Flow) this.flows.get(i);
472+// c.box.textShape(path,
473+// x - c.pageAxis - c.box.getWidth(), y);
474+// }
475+// break;
476+// default:
477+// throw new IllegalStateException();
478+// }
479+// }
451480
452481 public final void drawFloatings(PageBox pageBox, Drawer drawer, Visitor visitor, Shape clip,
453482 AffineTransform transform, double contextX, double contextY, double x, double y) {
--- copper/trunk/homare/src/main/java/jp/cssj/homare/style/box/params/Background.java (revision 1625)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/style/box/params/Background.java (revision 1626)
@@ -4,10 +4,10 @@
44 import java.awt.geom.AffineTransform;
55 import java.awt.geom.Rectangle2D;
66
7+import jp.cssj.homare.css.value.PaintValue;
78 import jp.cssj.homare.style.util.BorderRenderer;
89 import jp.cssj.sakae.gc.GC;
910 import jp.cssj.sakae.gc.GraphicsException;
10-import jp.cssj.sakae.gc.paint.Color;
1111 import jp.cssj.sakae.gc.paint.Pattern;
1212
1313 /**
@@ -20,7 +20,7 @@
2020 /**
2121 * 背景色です。nullの場合は背景を塗りません。
2222 */
23- private final Color backgroundColor;
23+ private final PaintValue backgroundPaint;
2424
2525 /**
2626 * 背景画像です。nullの場合は背景画像を描きません。
@@ -45,15 +45,15 @@
4545 */
4646 public static final Background NULL_BACKGROUND = new Background(null, null, BORDER_BOX);
4747
48- public static Background create(Color backgroundColor, BackgroundImage backgroundImage, byte backgroundCiip) {
49- if (backgroundColor == null && backgroundImage == null) {
48+ public static Background create(PaintValue backgroundPaint, BackgroundImage backgroundImage, byte backgroundCiip) {
49+ if (backgroundPaint == null && backgroundImage == null) {
5050 return NULL_BACKGROUND;
5151 }
52- return new Background(backgroundColor, backgroundImage, backgroundCiip);
52+ return new Background(backgroundPaint, backgroundImage, backgroundCiip);
5353 }
5454
55- private Background(Color backgroundColor, BackgroundImage backgroundImage, byte backgroundClip) {
56- this.backgroundColor = backgroundColor;
55+ private Background(PaintValue backgroundPaint, BackgroundImage backgroundImage, byte backgroundClip) {
56+ this.backgroundPaint = backgroundPaint;
5757 this.backgroundImage = backgroundImage;
5858 this.backgroundClip = backgroundClip;
5959 }
@@ -63,8 +63,8 @@
6363 *
6464 * @return
6565 */
66- public Color getBackgroundColor() {
67- return this.backgroundColor;
66+ public PaintValue getBackgroundPaint() {
67+ return this.backgroundPaint;
6868 }
6969
7070 /**
@@ -112,6 +112,7 @@
112112 switch (this.backgroundClip) {
113113 case BORDER_BOX:
114114 case PADDING_BOX:
115+ case TEXT: // TODO
115116 shape = new Rectangle2D.Double(x, y, width, height);
116117 break;
117118 case CONTENT_BOX:
@@ -124,6 +125,7 @@
124125 } else {
125126 switch (this.backgroundClip) {
126127 case BORDER_BOX:
128+ case TEXT: // TODO
127129 shape = BorderRenderer.SHARED_INSTANCE.getBorderShape(border, x, y, width, height);
128130 break;
129131 case PADDING_BOX:
@@ -147,9 +149,9 @@
147149 * }
148150 *//* Android end */
149151 gc.begin();
150- if (this.backgroundColor != null) {
152+ if (this.backgroundPaint != null) {
151153 // 背景色
152- gc.setFillPaint(this.backgroundColor);
154+ gc.setFillPaint(this.backgroundPaint.getPaint(shape.getBounds()));
153155 gc.fill(shape);
154156 }
155157 if (this.backgroundImage != null) {
@@ -297,10 +299,10 @@
297299 * @return
298300 */
299301 public boolean isVisible() {
300- return this.getBackgroundColor() != null || this.getBackgroundImage() != null;
302+ return this.getBackgroundPaint() != null || this.getBackgroundImage() != null;
301303 }
302304
303305 public String toString() {
304- return super.toString() + "[color=" + this.getBackgroundColor() + ",image=" + this.getBackgroundImage() + "]";
306+ return super.toString() + "[paint=" + this.getBackgroundPaint() + ",image=" + this.getBackgroundImage() + "]";
305307 }
306308 }
\ No newline at end of file
--- copper/trunk/sakae/sakae-core/src/main/java/jp/cssj/sakae/gc/paint/LinearGradient.java (revision 1625)
+++ copper/trunk/sakae/sakae-core/src/main/java/jp/cssj/sakae/gc/paint/LinearGradient.java (revision 1626)
@@ -60,4 +60,9 @@
6060 public AffineTransform getTransform() {
6161 return this.transform;
6262 }
63+
64+ public String toString() {
65+ return super.toString() + "[x1=" + x1 + ",y1=" + y1 + ",x2=" + x2 + ",y2=" + y2 + ",fractions=" + fractions
66+ + ",colors=" + colors+ ",transform=" + transform + "]";
67+ }
6368 }
--- copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/gc/PdfGC.java (revision 1625)
+++ copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/gc/PdfGC.java (revision 1626)
@@ -896,7 +896,7 @@
896896 default:
897897 throw new IllegalStateException();
898898 }
899- if (enlargement > 0) {
899+ if (enlargement > 0 && this.fillPaint.getPaintType() == Paint.COLOR) {
900900 this.q();
901901 localContext = true;
902902 this.out.writeReal(enlargement);
@@ -1004,7 +1004,7 @@
10041004 // テキスト終了
10051005 this.out.writeOperator("ET");
10061006
1007- if (enlargement > 0) {
1007+ if (enlargement > 0 && this.fillPaint.getPaintType() == Paint.COLOR) {
10081008 // Bold終了
10091009 this.out.writeInt(TEXT_MODE_FILL);
10101010 this.out.writeOperator("Tr");
Show on old repository browser