diff --git a/gallery/test.json b/gallery/test.json index fc15e6d..f247bea 100644 --- a/gallery/test.json +++ b/gallery/test.json @@ -101,5 +101,11 @@ } } } + }, + "colors": { + "main": { + "31-28": "#FF0000", + "11-4": [34, 176, 43] + } } } diff --git a/gallery/test.pdf b/gallery/test.pdf index 925be2c..d08058f 100644 Binary files a/gallery/test.pdf and b/gallery/test.pdf differ diff --git a/gallery/test.xml b/gallery/test.xml index ab92e22..4a8b716 100644 --- a/gallery/test.xml +++ b/gallery/test.xml @@ -65,4 +65,7 @@ offset register + + + \ No newline at end of file diff --git a/gallery/test.yaml b/gallery/test.yaml index 2ca7964..f7119ae 100644 --- a/gallery/test.yaml +++ b/gallery/test.yaml @@ -71,3 +71,11 @@ structures: 3-0: name: Rm description: offset register + +colors: + main: + 31-28: "#3EFA6B" + 25-23: + - 100 + - 150 + - 200 \ No newline at end of file diff --git a/src/schema.typ b/src/schema.typ index 0602329..5c1f650 100644 --- a/src/schema.typ +++ b/src/schema.typ @@ -50,6 +50,28 @@ parse-raw(path-or-schema) } + if "colors" in schema { + for struct in schema.colors.keys() { + for (span, col) in schema.colors.at(struct) { + if type(col) == str { + if col.starts-with("#") { + col = rgb(col) + } else { + let (r, g, b) = col.split(",").map(v => int(v)) + col = rgb(r, g, b) + } + } else if type(col) == array { + col = rgb(..col) + } else if type(col) != color { + panic("Invalid color format") + } + schema.colors.at(struct).at(span) = col + } + } + } else { + schema.insert("colors", (:)) + } + let structures = (:) for (id, data) in schema.structures { id = str(id) diff --git a/src/xml-loader.typ b/src/xml-loader.typ index 1f00c42..9513766 100644 --- a/src/xml-loader.typ +++ b/src/xml-loader.typ @@ -83,8 +83,10 @@ #let parse(content) = { let struct-elmts = content.children.filter(e => "tag" in e and e.tag == "structure") + let color-elmts = content.children.filter(e => "tag" in e and e.tag == "color") let structures = (:) + let colors = (:) for struct-elmt in struct-elmts { structures.insert( @@ -93,8 +95,19 @@ ) } + for color-elmt in color-elmts { + let struct = color-elmt.attrs.structure + if not struct in colors { + colors.insert(struct, (:)) + } + + let span = color-elmt.attrs.end + "-" + color-elmt.attrs.start + colors.at(struct).insert(span, color-elmt.attrs.color) + } + return ( - structures: structures + structures: structures, + colors: colors ) }