summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKhaled Hosny <khaledhosny@eglug.org>2010-09-13 05:19:36 +0300
committerKhaled Hosny <khaledhosny@eglug.org>2010-09-13 05:19:36 +0300
commit0e63b6f673544a52078da0981a245d6a03ab9dbd (patch)
treeebddc7cdd2b397fd8e8c108443a5247618d486f6
parent7ae4943ae02f085a8826258bec3a654e830776ac (diff)
downloadluaotfload-0e63b6f673544a52078da0981a245d6a03ab9dbd.tar.gz
Sanitize color before attempting to use it
Right now it just checks the number if fields, may be we should check if it is a valid hex color value as well.
-rw-r--r--otfl-font-clr.lua16
-rw-r--r--tests/sanitize_color.tex8
2 files changed, 23 insertions, 1 deletions
diff --git a/otfl-font-clr.lua b/otfl-font-clr.lua
index a6cf63f..dc14b2c 100644
--- a/otfl-font-clr.lua
+++ b/otfl-font-clr.lua
@@ -15,8 +15,22 @@ local initializers, format = fonts.initializers, string.format
table.insert(fonts.triggers,"color")
function initializers.common.color(tfmdata,value)
+ local sanitized
+
if value then
- tfmdata.color = tostring(value)
+ if #value == 6 or #value == 8 then
+ sanitized = value
+ elseif #value == 7 then
+ _, _, sanitized = value:find("(......)")
+ elseif #value > 8 then
+ _, _, sanitized = value:find("(........)")
+ else
+ -- broken color code ignored, issue a warning?
+ end
+ end
+
+ if sanitized then
+ tfmdata.color = sanitized
add_color_callback()
end
end
diff --git a/tests/sanitize_color.tex b/tests/sanitize_color.tex
new file mode 100644
index 0000000..fe95d37
--- /dev/null
+++ b/tests/sanitize_color.tex
@@ -0,0 +1,8 @@
+\input luaotfload.sty
+\font\testa={name:Latin Modern Roman:color=0000ff99f} at 10pt
+\font\testb={name:Latin Modern Roman:color=0000ff9} at 10pt
+\font\testc={name:Latin Modern Roman:color=0000f} at 10pt
+\testa test\par
+\testb test\par
+\testc test\par
+\bye