ref: ea67cece3186dc5ef0b8e5ca985ef76325c4ae59
parent: e9c71defb4cb0c00ee99738bd740b959e4e110d0
author: Philip Silva <[email protected]>
date: Mon Jan 4 14:27:52 EST 2021
fix bg artifacts
--- a/browser/browser.go
+++ b/browser/browser.go
@@ -240,7 +240,6 @@
}
var i *draw.Image
- var err error
w := n.Width()
h := n.Height()
@@ -247,7 +246,10 @@
if w == 0 && h == 0 {
return NewElement(ui, n)
}
- if i, err = n.BoxBackground(); err != nil {
+ if bg, err := n.BoxBackground(); err == nil {
+ _=bg
+ //i = bg
+ } else {
log.Printf("box background: %f", err)
}
box := &duit.Box{
--- a/img/img.go
+++ b/img/img.go
@@ -8,7 +8,7 @@
"github.com/srwiley/oksvg"
"github.com/srwiley/rasterx"
"image"
- "image/jpeg"
+ "image/png"
"io"
"github.com/psilva261/opossum"
"github.com/psilva261/opossum/logger"
@@ -82,7 +82,7 @@
icon.Draw(rasterx.NewDasher(w, h, rasterx.NewScannerGV(w, h, rgba, rgba.Bounds())), 1)
buf := bytes.NewBufferString("")
- if err = jpeg.Encode(buf, rgba, nil); err != nil {
+ if err = png.Encode(buf, rgba); err != nil {
return nil, fmt.Errorf("encode: %w", err)
}
@@ -124,10 +124,11 @@
// Encode uses a Writer, use a Buffer if you need the raw []byte
buf := bytes.NewBufferString("")
- if err = jpeg.Encode(buf, newImage, nil); err != nil {
+ if err = png.Encode(buf, newImage); err != nil {
return nil, fmt.Errorf("encode: %w", err)
}
data = buf.Bytes()
}
+
return bytes.NewReader(data), nil
}
--- a/style/experimental.go
+++ b/style/experimental.go
@@ -56,13 +56,21 @@
func (cs Map) backgroundColor() draw.Color {
_, ok := cs.Declarations["background-color"]
if ok {
- return draw.Color(cs.colorHex("background-color"))
+ c, ok := cs.colorHex("background-color")
+ if !ok {
+ return draw.White
+ }
+ return c
}
_, ok = cs.Declarations["background"]
if ok {
- return draw.Color(cs.colorHex("background"))
+ c, ok := cs.colorHex("background")
+ if !ok {
+ return draw.White
+ }
+ return c
}
- return draw.Color(uint32(draw.White))
+ return draw.White
}
func backgroundImageUrl(decl css.Declaration) (url string, ok bool) {
--- a/style/stylesheets.go
+++ b/style/stylesheets.go
@@ -362,15 +362,18 @@
}
func (cs Map) Color() draw.Color {
- h := cs.colorHex("color")
+ h, ok := cs.colorHex("color")
+ if !ok {
+ return draw.Black
+ }
c := draw.Color(h)
return c
}
-func (cs Map) colorHex(cssPropName string) uint32 {
+func (cs Map) colorHex(cssPropName string) (c draw.Color, ok bool) {
propVal, ok := cs.Declarations[cssPropName]
if ok {
- var r, g, b, a uint32
+ var r, g, b uint32
if strings.HasPrefix(propVal.Value, "rgb") {
val := propVal.Value[3:]
val = strings.TrimPrefix(val, "(")
@@ -393,7 +396,7 @@
b = uint32(bb) * 256
} else if strings.HasPrefix(propVal.Value, "#") {
hexColor := propVal.Value[1:]
- a = 256 * 256
+
if len(hexColor) == 3 {
rr, err := strconv.ParseInt(hexColor[0:1], 16, 32)
if err != nil {
@@ -437,30 +440,21 @@
if !ok {
goto default_value
}
- r, g, b, a = colorRGBA.RGBA()
+ r, g, b, _ = colorRGBA.RGBA()
}
- m := uint32(16)
- downSample := func(a uint32) uint32 {
- return a
- return a - (a % m)
- }
- x := (downSample(r / 256)) << 24
- x = x | (downSample((g / 256)) << 16)
- x = x | (downSample((b / 256)) << 8)
- //x = x | (a / 256)
- _ = a
+
+ x := (r / 256) << 24
+ x = x | ((g / 256) << 16)
+ x = x | ((b / 256) << 8)
x = x | 0x000000ff
- if x == 0xffffffff {
- // TODO: white on white background...
- return uint32(draw.Black)
- }
- return uint32(x)
+
+ return draw.Color(uint32(x)), true
} else {
- return uint32(draw.Black)
+ return 0, false
}
default_value:
log.Printf("could not interpret %v", propVal)
- return uint32(draw.Black)
+ return 0, false
}
func (cs Map) IsInline() bool {
--- a/style/stylesheets_test.go
+++ b/style/stylesheets_test.go
@@ -30,8 +30,16 @@
tr := d("red")
hr := d("#ff0000")
- tri := tr.colorHex("color")
- hri := hr.colorHex("color")
+ tri, ok := tr.colorHex("color")
+ if !ok {
+ t.Fail()
+ }
+
+ hri, ok := hr.colorHex("color")
+ if !ok {
+ t.Fail()
+ }
+
if tri != hri {
t.Fatalf("tri=%x hri=%x", tri, hri)
}