29 #include "../lout/msg.h" 48 Length backgroundPositionX,
49 Length backgroundPositionY,
50 int xDraw,
int yDraw,
int widthDraw,
51 int heightDraw,
int xRef,
int yRef,
52 int widthRef,
int heightRef,
53 bool *repeatX,
bool *repeatY,
54 int *origX,
int *origY,
55 int *tileX1,
int *tileX2,
int *tileY1,
56 int *tileY2,
bool *doDraw);
58 void StyleAttrs::initValues ()
61 x_lang[0] = x_lang[1] = 0;
71 backgroundColor = NULL;
72 backgroundImage = NULL;
80 borderWidth.setVal (0);
83 setBorderColor (NULL);
98 void StyleAttrs::resetValues ()
104 backgroundColor = NULL;
105 backgroundImage = NULL;
114 borderWidth.setVal (0);
116 setBorderColor (NULL);
145 return this == otherAttrs ||
146 (font == otherAttrs->
font &&
148 color == otherAttrs->
color &&
156 valign == otherAttrs->
valign &&
162 width == otherAttrs->
width &&
163 height == otherAttrs->
height &&
166 margin.equals (&otherAttrs->
margin) &&
168 padding.equals (&otherAttrs->
padding) &&
178 display == otherAttrs->
display &&
182 cursor == otherAttrs->
cursor &&
183 x_link == otherAttrs->
x_link &&
184 x_lang[0] == otherAttrs->
x_lang[0] &&
185 x_lang[1] == otherAttrs->
x_lang[1] &&
186 x_img == otherAttrs->
x_img &&
190 int StyleAttrs::hashValue () {
191 return (intptr_t) font +
194 (intptr_t) backgroundColor +
195 (intptr_t) backgroundImage +
197 backgroundAttachment +
198 backgroundPositionX +
199 backgroundPositionY +
212 borderWidth.hashValue () +
213 padding.hashValue () +
215 (intptr_t) borderColor.top +
216 (intptr_t) borderColor.right +
217 (intptr_t) borderColor.bottom +
218 (intptr_t) borderColor.left +
229 x_lang[0] + x_lang[1] +
231 (intptr_t) x_tooltip;
234 int Style::totalRef = 0;
260 backgroundColor->ref ();
262 backgroundImage->ref ();
264 borderColor.top->ref();
265 if (borderColor.bottom)
266 borderColor.bottom->ref();
267 if (borderColor.left)
268 borderColor.left->ref();
269 if (borderColor.right)
270 borderColor.right->ref();
284 backgroundColor->unref ();
286 backgroundImage->unref ();
288 borderColor.top->unref();
289 if (borderColor.bottom)
290 borderColor.bottom->unref();
291 if (borderColor.left)
292 borderColor.left->unref();
293 if (borderColor.right)
294 borderColor.right->unref();
298 styleTable->remove (
this);
308 color = attrs->
color;
322 width = attrs->
width;
338 x_lang[0] = attrs->
x_lang[0];
339 x_lang[1] = attrs->
x_lang[1];
340 x_img = attrs->
x_img;
350 this == otherAttrs ||
351 (size == otherAttrs->
size &&
352 weight == otherAttrs->
weight &&
353 style == otherAttrs->
style &&
356 strcmp (name, otherAttrs->
name) == 0);
359 int FontAttrs::hashValue()
362 h = (h << 5) - h + size;
363 h = (h << 5) - h + weight;
364 h = (h << 5) - h + style;
365 h = (h << 5) - h + letterSpacing;
366 h = (h << 5) - h + fontVariant;
378 name = strdup (attrs->
name);
381 style = attrs->
style;
389 return layout->
createFont (attrs, tryEverything);
394 return create0 (layout, attrs,
false);
397 bool Font::exists (
Layout *layout,
const char *name)
407 return this == oc || (color == oc->
color);
410 int ColorAttrs::hashValue()
420 int Color::shadeColor (
int color,
int d)
422 int red = (color >> 16) & 255;
423 int green = (color >> 8) & 255;
424 int blue = color & 255;
426 double oldLightness = ((double)
misc::max (red, green, blue)) / 255;
429 if (oldLightness > 0.8) {
431 newLightness = oldLightness - 0.2;
433 newLightness = oldLightness - 0.4;
434 }
else if (oldLightness < 0.2) {
436 newLightness = oldLightness + 0.4;
438 newLightness = oldLightness + 0.2;
440 newLightness = oldLightness + d * 0.2;
443 double f = (newLightness / oldLightness);
444 red = (int)(red * f);
445 green = (int)(green * f);
446 blue = (int)(blue * f);
448 red = green = blue = (int)(newLightness * 255);
451 return (red << 16) | (green << 8) | blue;
454 int Color::shadeColor (
int color,
Shading shading)
461 return shadeColor(color, +1);
463 case SHADING_INVERSE:
464 return color ^ 0xffffff;
467 return shadeColor(color, -1);
491 void StyleImage::StyleImgRenderer::setBuffer (
core::Imgbuf *buffer,
bool resize)
493 if (image->imgbufSrc)
494 image->imgbufSrc->
unref ();
495 if (image->imgbufTiled)
496 image->imgbufTiled->unref ();
498 image->imgbufTiled = NULL;
500 image->imgbufSrc = buffer;
503 if (image->imgbufSrc) {
504 image->imgbufSrc->ref ();
517 if (image->imgbufSrc->getRootWidth() * image->imgbufSrc->getRootHeight()
524 image->imgbufSrc->createSimilarBuf
525 (image->tilesX * image->imgbufSrc->getRootWidth(),
526 image->tilesY * image->imgbufSrc->getRootHeight());
533 void StyleImage::StyleImgRenderer::drawRow (
int row)
535 if (image->imgbufTiled) {
547 int w = image->imgbufSrc->getRootWidth ();
548 int h = image->imgbufSrc->getRootHeight ();
550 for (
int x = 0; x < image->tilesX; x++)
551 for (
int y = 0; y < image->tilesX; y++)
552 image->imgbufSrc->copyTo (image->imgbufTiled, x * w, y * h,
557 void StyleImage::StyleImgRenderer::finish ()
562 void StyleImage::StyleImgRenderer::fatal ()
567 StyleImage::StyleImage ()
577 imgRendererDist->put (styleImgRenderer);
580 StyleImage::~StyleImage ()
585 imgbufTiled->unref ();
587 delete imgRendererDist;
588 delete styleImgRenderer;
599 void StyleImage::ExternalImgRenderer::drawRow (
int row)
603 if (readyToDraw () && (backgroundImage = getBackgroundImage ())) {
610 int x, y, width, height;
611 getBgArea (&x, &y, &width, &height);
613 int xRef, yRef, widthRef, heightRef;
614 getRefArea (&xRef, &yRef, &widthRef, &heightRef);
616 bool repeatX, repeatY, doDraw;
617 int origX, origY, tileX1, tileX2, tileY1, tileY2;
620 getBackgroundRepeat (),
621 getBackgroundAttachment (),
622 getBackgroundPositionX (),
623 getBackgroundPositionY (),
624 x, y, width, height, xRef, yRef, widthRef,
625 heightRef, &repeatX, &repeatY, &origX,
626 &origY, &tileX1, &tileX2, &tileY1,
635 for (
int tileY = tileY1; tileY <= tileY2; tileY++) {
636 int x1 =
misc::max (origX + tileX1 * imgWidth, x);
637 int x2 =
misc::min (origX + (tileX2 + 1) * imgWidth, x + width);
639 int yt = origY + tileY * imgHeight + row;
640 if (yt >= y && yt < y + height)
641 draw (x1, yt, x2 - x1, 1);
647 void StyleImage::ExternalImgRenderer::finish ()
650 if (readyToDraw ()) {
652 int x, y, width, height;
653 getBgArea (&x, &y, &width, &height);
654 draw (x, y, width, height);
659 void StyleImage::ExternalImgRenderer::fatal ()
666 StyleImage *StyleImage::ExternalWidgetImgRenderer::getBackgroundImage ()
668 Style *style = getStyle ();
674 Style *style = getStyle ();
679 StyleImage::ExternalWidgetImgRenderer::getBackgroundAttachment ()
681 Style *style = getStyle ();
685 Length StyleImage::ExternalWidgetImgRenderer::getBackgroundPositionX ()
687 Style *style = getStyle ();
691 Length StyleImage::ExternalWidgetImgRenderer::getBackgroundPositionY ()
693 Style *style = getStyle ();
707 int x1,
int y1,
int x2,
int y2)
712 const bool filled =
true, convex =
true;
713 bool ridge =
false, inset =
false, dotted =
false;
729 w, x1+w/2, y1+w/2, x2-w/2, y2+w/2);
736 shading = (inset) ? Color::SHADING_DARK : Color::SHADING_LIGHT;
742 points[1].
x = x2 + 1;
743 points[0].
y = points[1].
y = y1;
756 points[1].
x = x2 + 1;
757 points[0].
y = points[1].
y = y1;
761 shading = (ridge) ? Color::SHADING_LIGHT : Color::SHADING_DARK;
770 shading = (ridge) ? Color::SHADING_DARK : Color::SHADING_LIGHT;
784 points[1].
x = x2 + 1;
785 points[0].
y = points[1].
y = y1;
786 points[2].
x = points[1].
x - w_r;
787 points[3].
x = points[0].
x + w_l;
788 points[2].
y = points[3].
y = points[0].
y + w;
793 points[0].
y = points[1].
y = y1 + w + d;
804 int x1,
int y1,
int x2,
int y2)
809 const bool filled =
true, convex =
true;
810 bool ridge =
false, inset =
false, dotted =
false;
826 w, x1+w/2, y1-w/2, x2-w/2, y2-w/2);
833 shading = (inset) ? Color::SHADING_LIGHT : Color::SHADING_DARK;
838 points[0].
x = x1 - 1;
839 points[1].
x = x2 + 2;
840 points[0].
y = points[1].
y = y1 + 1;
853 points[0].
x = x1 - 1;
854 points[1].
x = x2 + 2 - d;
855 points[0].
y = points[1].
y = y1 + 1;
858 points[2].
y = points[3].
y = points[0].
y - w/2 - d;
859 shading = (ridge) ? Color::SHADING_DARK : Color::SHADING_LIGHT;
865 points[0].
y = points[1].
y = y1 - w + 1;
868 points[2].
y = points[3].
y = points[0].
y + w/2;
869 shading = (ridge) ? Color::SHADING_LIGHT : Color::SHADING_DARK;
882 points[0].
x = x2 + 2;
883 points[1].
x = x1 - 1;
884 points[0].
y = points[1].
y = y1 + 1;
885 points[2].
x = points[1].
x + w_l;
886 points[3].
x = points[0].
x - w_r;
887 points[2].
y = points[3].
y = points[0].
y - w;
892 points[0].
y = points[1].
y = y1 + 1 - w - d;
903 int x1,
int y1,
int x2,
int y2)
908 bool filled =
true, convex =
true;
909 bool ridge =
false, inset =
false, dotted =
false;
925 w, x1+w/2, y1+w/2, x1+w/2, y2-w/2);
932 shading = (inset) ? Color::SHADING_DARK : Color::SHADING_LIGHT;
936 points[0].
x = points[1].
x = x1;
937 points[0].
y = y1 - 1;
938 points[1].
y = y2 + 1;
951 points[0].
x = points[1].
x = x1;
954 points[2].
x = points[3].
x = x1 + w / 2 + d;
957 shading = (ridge) ? Color::SHADING_LIGHT : Color::SHADING_DARK;
960 points[0].
x = points[1].
x = x1 + w / 2 + d;
963 points[2].
x = points[3].
x = x1 + w;
966 shading = (ridge) ? Color::SHADING_DARK : Color::SHADING_LIGHT;
979 points[0].
x = points[1].
x = x1;
980 points[0].
y = y1 - 1;
981 points[1].
y = y2 + 1;
982 points[2].
x = points[3].
x = points[0].
x + w;
983 points[2].
y = points[1].
y - w_b;
984 points[3].
y = points[0].
y + w_t;
987 points[0].
x = points[1].
x = x1 + w + d;
990 points[2].
x = points[3].
x = points[0].
x + w;
1000 int x1,
int y1,
int x2,
int y2)
1005 const bool filled =
true, convex =
true;
1006 bool ridge =
false, inset =
false, dotted =
false;
1022 w, x1 - w/2, y1 + w/2, x1 - w/2, y2 - w/2);
1029 shading = (inset) ? Color::SHADING_LIGHT : Color::SHADING_DARK;
1033 points[0].
x = points[1].
x = x1 + 1;
1034 points[0].
y = y1 - 1;
1035 points[1].
y = y2 + 1;
1048 points[0].
x = points[1].
x = x1 + 1;
1051 points[2].
x = points[3].
x = points[0].
x - w / 2 - d;
1054 shading = (ridge) ? Color::SHADING_DARK : Color::SHADING_LIGHT;
1057 points[0].
x = points[1].
x = x1 + 1 - w / 2 - d;
1060 points[2].
x = points[3].
x = x1 + 1 - w;
1063 shading = (ridge) ? Color::SHADING_LIGHT: Color::SHADING_DARK;
1076 points[0].
x = points[1].
x = x1 + 1;
1077 points[0].
y = y1 - 1;
1078 points[1].
y = y2 + 1;
1079 points[2].
x = points[3].
x = points[0].
x - w;
1080 points[2].
y = points[1].
y - w_b;
1081 points[3].
y = points[0].
y + w_t;
1084 points[0].
x = points[1].
x = x1 + 1 - w - d;
1087 points[2].
x = points[3].
x = points[0].
x - w;
1105 int x,
int y,
int width,
int height,
1106 Style *style,
bool inverse)
1109 int xb1, yb1, xb2, yb2;
1114 xb2 = x + (width > 0 ? width - 1 : 0) - style->
margin.
right;
1115 yb2 = y + (height > 0 ? height - 1 : 0) - style->
margin.
bottom;
1162 int x,
int y,
int width,
int height,
1163 int xRef,
int yRef,
int widthRef,
int heightRef,
1164 Style *style,
bool inverse,
bool atTop)
1185 if (bgColor || bgImage) {
1189 bgArea.
width = width;
1196 Color::SHADING_INVERSE : Color::SHADING_NORMAL,
1197 true, intersection.
x, intersection.
y,
1206 intersection.
x, intersection.
y,
1208 xRef, yRef, widthRef, heightRef);
1217 Length backgroundPositionX,
1218 Length backgroundPositionY,
1219 int x,
int y,
int width,
int height,
1220 int xRef,
int yRef,
int widthRef,
int heightRef)
1226 bool repeatX, repeatY, doDraw;
1227 int origX, origY, tileX1, tileX2, tileY1, tileY2;
1230 backgroundAttachment, backgroundPositionX,
1231 backgroundPositionY, x, y, width, height,
1232 xRef, yRef, widthRef, heightRef,
1233 &repeatX, &repeatY, &origX, &origY,
1234 &tileX1, &tileX2, &tileY1, &tileY2, &doDraw);
1250 int tilesX = backgroundImage->
getTilesX (repeatX, repeatY);
1251 int tilesY = backgroundImage->
getTilesY (repeatX, repeatY);
1253 for (
int tileX = tileX1; tileX <= tileX2; tileX += tilesX)
1254 for (
int tileY = tileY1; tileY <= tileY2; tileY += tilesY) {
1255 int xt = origX + tileX * imgWidthS;
1257 int x2 =
misc::min (xt + imgWidthT, x + width);
1258 int yt = origY + tileY * imgHeightS;
1260 int y2 =
misc::min (yt + imgHeightT, y + height);
1262 view->
drawImage (imgbufT, xt, yt, x1 - xt, y1 - yt,
1271 Length backgroundPositionX,
1272 Length backgroundPositionY,
1273 int xDraw,
int yDraw,
int widthDraw,
1274 int heightDraw,
int xRef,
int yRef,
1275 int widthRef,
int heightRef,
bool *repeatX,
1276 bool *repeatY,
int *origX,
int *origY,
1277 int *tileX1,
int *tileX2,
int *tileY1,
1278 int *tileY2,
bool *doDraw)
1298 *tileX1 = xDraw < *origX ?
1299 - (*origX - xDraw + imgWidth - 1) / imgWidth :
1300 (xDraw - *origX) / imgWidth;
1301 *tileX2 = *origX < xDraw + widthDraw ?
1302 (xDraw + widthDraw - *origX - 1) / imgWidth :
1303 - (*origX - (xDraw + widthDraw) + imgWidth - 1) / imgWidth;
1304 *tileY1 = yDraw < *origY ?
1305 - (*origY - yDraw + imgHeight - 1) / imgHeight :
1306 (yDraw - *origY) / imgHeight;
1307 *tileY2 = *origY < yDraw + heightDraw ?
1308 (yDraw + heightDraw - *origY - 1) / imgHeight :
1309 - (*origY - (yDraw + heightDraw) + imgHeight - 1) / imgHeight;
1314 if (*tileX1 <= 0 && *tileX2 >= 0)
1316 *tileX1 = *tileX2 = 0;
1324 if (*tileY1 <= 0 && *tileY2 >= 0)
1325 *tileY1 = *tileY2 = 0;
1334 *
const roman_I0[] = {
"",
"I",
"II",
"III",
"IV",
"V",
"VI",
"VII",
"VIII",
"IX" },
1335 *
const roman_I1[] = {
"",
"X",
"XX",
"XXX",
"XL",
"L",
"LX",
"LXX",
"LXXX",
"XC" },
1336 *
const roman_I2[] = {
"",
"C",
"CC",
"CCC",
"CD",
"D",
"DC",
"DCC",
"DCCC",
"CM" },
1359 switch(listStyleType){
1366 i1 = i0/26 - 1; i2 = i1/26 - 1;
1368 snprintf(buf, buflen,
"****.");
1370 snprintf(buf, buflen,
"%c%c%c.",
1371 i2<0 ?
' ' : start_ch + i2%26,
1372 i1<0 ?
' ' : start_ch + i1%26,
1373 i0<0 ?
' ' : start_ch + i0%26);
1379 i1 = i0/10; i2 = i1/10; i3 = i2/10;
1380 i0 %= 10; i1 %= 10; i2 %= 10;
1381 if (num < 0 || i3 > 4)
1382 snprintf(buf, buflen,
"****.");
1389 snprintf(buf, buflen,
"%d.", num);
1394 buf[buflen - 1] =
'\0';