+2010-11-24 Lars Magne Ingebrigtsen <larsi@gnus.org>
+
+ * shr.el (shr-color-check): Protect against non-existant colour names.
+
+2010-11-24 Julien Danjou <julien@danjou.info>
+
+ * shr.el (shr-insert-color-overlay): Remove specific rgb() check.
+
+ * shr-color.el (shr-color->hexadecimal): Only return the hexadecimal
+ matched part.
+
+ * color-lab.el: Fix all expt calls to use float type.
+
2010-11-24 Katsumi Yamaoka <yamaoka@jpl.org>
* shr.el (shr-insert-color-overlay): Pass rgb(rrr, ggg, bbb) type color
(let* ((fy (/ (+ L 16) 116.0))
(fz (- fy (/ b 200.0)))
(fx (+ (/ a 500.0) fy))
- (xr (if (> (expt fx 3) color-lab-ε)
- (expt fx 3)
+ (xr (if (> (expt fx 3.0) color-lab-ε)
+ (expt fx 3.0)
(/ (- (* fx 116) 16) color-lab-κ)))
(yr (if (> L (* color-lab-κ color-lab-ε))
- (expt (/ (+ L 16) 116.0) 3)
+ (expt (/ (+ L 16) 116.0) 3.0)
(/ L color-lab-κ)))
(zr (if (> (expt fz 3) color-lab-ε)
- (expt fz 3)
+ (expt fz 3.0)
(/ (- (* 116 fz) 16) color-lab-κ))))
(list (* xr Xr) ; X
(* yr Yr) ; Y
(let* ((kL (or kL 1))
(kC (or kC 1))
(kH (or kH 1))
- (C₁ (sqrt (+ (expt a₁ 2) (expt b₁ 2))))
- (C₂ (sqrt (+ (expt a₂ 2) (expt b₂ 2))))
+ (C₁ (sqrt (+ (expt a₁ 2.0) (expt b₁ 2.0))))
+ (C₂ (sqrt (+ (expt a₂ 2.0) (expt b₂ 2.0))))
(C̄ (/ (+ C₁ C₂) 2.0))
- (G (* 0.5 (- 1 (sqrt (/ (expt C̄ 7) (+ (expt C̄ 7) (expt 25 7)))))))
+ (G (* 0.5 (- 1 (sqrt (/ (expt C̄ 7.0) (+ (expt C̄ 7.0) (expt 25 7.0)))))))
(a′₁ (* (+ 1 G) a₁))
(a′₂ (* (+ 1 G) a₂))
- (C′₁ (sqrt (+ (expt a′₁ 2) (expt b₁ 2))))
- (C′₂ (sqrt (+ (expt a′₂ 2) (expt b₂ 2))))
+ (C′₁ (sqrt (+ (expt a′₁ 2.0) (expt b₁ 2.0))))
+ (C′₂ (sqrt (+ (expt a′₂ 2.0) (expt b₂ 2.0))))
(h′₁ (if (and (= b₁ 0) (= a′₁ 0))
0
(let ((v (atan b₁ a′₁)))
(* 0.24 (cos (* h̄′ 2)))
(* 0.32 (cos (+ (* h̄′ 3) (degrees-to-radians 6))))
(- (* 0.20 (cos (- (* h̄′ 4) (degrees-to-radians 63)))))))
- (Δθ (* (degrees-to-radians 30) (exp (- (expt (/ (- h̄′ (degrees-to-radians 275)) (degrees-to-radians 25)) 2)))))
- (Rc (* 2 (sqrt (/ (expt C̄′ 7) (+ (expt C̄′ 7) (expt 25 7))))))
- (Sl (+ 1 (/ (* 0.015 (expt (- L̄′ 50) 2)) (sqrt (+ 20 (expt (- L̄′ 50) 2))))))
+ (Δθ (* (degrees-to-radians 30) (exp (- (expt (/ (- h̄′ (degrees-to-radians 275)) (degrees-to-radians 25)) 2.0)))))
+ (Rc (* 2 (sqrt (/ (expt C̄′ 7.0) (+ (expt C̄′ 7.0) (expt 25.0 7.0))))))
+ (Sl (+ 1 (/ (* 0.015 (expt (- L̄′ 50) 2.0)) (sqrt (+ 20 (expt (- L̄′ 50) 2.0))))))
(Sc (+ 1 (* C̄′ 0.045)))
(Sh (+ 1 (* 0.015 C̄′ T)))
(Rt (- (* (sin (* Δθ 2)) Rc))))
- (sqrt (+ (expt (/ ΔL′ (* Sl kL)) 2)
- (expt (/ ΔC′ (* Sc kC)) 2)
- (expt (/ ΔH′ (* Sh kH)) 2)
+ (sqrt (+ (expt (/ ΔL′ (* Sl kL)) 2.0)
+ (expt (/ ΔC′ (* Sc kC)) 2.0)
+ (expt (/ ΔH′ (* Sh kH)) 2.0)
(* Rt (/ ΔC′ (* Sc kC)) (/ ΔH′ (* Sh kH)))))))))
(provide 'color-lab)
(when color
(cond
;; Hexadecimal color: #abc or #aabbcc
- ((string-match-p
- "#[0-9a-fA-F]\\{3\\}[0-9a-fA-F]\\{3\\}?"
+ ((string-match
+ "\\(#[0-9a-fA-F]\\{3\\}[0-9a-fA-F]\\{3\\}?\\)"
color)
- color)
+ (match-string 1 color))
;; rgb() or rgba() colors
((or (string-match
"rgb(\s*\\([0-9]\\{1,3\\}\\(?:\s*%\\)?\\)\s*,\s*\\([0-9]\\{1,3\\}\\(?:\s*%\\)?\\)\s*,\s*\\([0-9]\\{1,3\\}\\(?:\s*%\\)?\\)\s*)"
(autoload 'shr-color->hexadecimal "shr-color")
(defun shr-color-check (fg &optional bg)
"Check that FG is visible on BG."
- (shr-color-visible (or (shr-color->hexadecimal bg)
- (frame-parameter nil 'background-color))
- (shr-color->hexadecimal fg) (not bg)))
+ (let ((hex-color (shr-color->hexadecimal fg)))
+ (when hex-color
+ (shr-color-visible (or (shr-color->hexadecimal bg)
+ (frame-parameter nil 'background-color))
+ hex-color (not bg)))))
(defun shr-insert-color-overlay (color start end)
(when color
- (when (and (not (string-match "\\`rgb([^\)]+)\\'" color))
- (string-match " " color))
- (setq color (car (split-string color))))
- (let ((overlay (make-overlay start end)))
- (overlay-put overlay 'face (cons 'foreground-color
- (cadr (shr-color-check color)))))))
+ (let ((new-color (cadr (shr-color-check color))))
+ (when new-color
+ (overlay-put (make-overlay start end) 'face
+ (cons 'foreground-color new-color))))))
;;; Tag-specific rendering rules.