SVG Tiny 与 Libsvgtiny
这是我的硕士论文笔记系列第二篇,原文写于 2016 年五月。
SVG Tiny 1.2 Spec
- The SVG Working Group does not provide a normative DTD for SVG Tiny 1.2 but instead provides a normative RelaxNG schema.
- How to reference this specification:
When referencing this specification as a whole or when referencing a chapter or major section, use the undated URI, http://www.w3.org/TR/SVGTiny12/ , where possible. This allows the reference to always refer to the latest version of this specification.
Scriptable
The combination of scripting and the HTML DOM is often termed “Dynamic HTML” and is widely used for animation, interactivity and presentational effects. Similarly SVG allows the script-based manipulation of the document tree us-ing a subset of the XML DOM and the SVG uDOM.
Rendering Model
- The painters model
- Types of graphics elements
- Shapes: lines, curves
- Text
- Repalced content
- Raster images
- Video
- Animation
- Foreign Objects
- Rendering shapes and text
- fill, stroke: independent, has opacity
- paint:
- Solid color
- Gradients (linear, radial)
Document Structure
svg
element:- version, baseProfile, width, height, viewBox, …
- This specification corresponds to baseProfile=”tiny” and version=”1.2” .
g
element:id
,xml: id
- 在 group 中的元素擁有 group 的屬性
defs
elementdiscard
elementtitle
anddesc
elementuse
elementimage
element: must reference content that is a raster image formatswitch
element: five conditional processing attributes- requiredExtensions
- requiredFeatures
- requiredFonts
- requiredFormats
- systemLanguage
prefetch
element- Attributes common to all elements: id, class, role, …
Animation
- mpath
Libsvgtiny
介紹
- Libsvgtiny is an implementation of SVG Tiny, written in C. It is currently in development for use with NetSurf and is intended to be suitable for use in other projects too.
- The overall idea of the library is to take some SVG as input, and return a list of paths and texts which can be rendered easily. The library does not do the actual rendering. For further details, see the readme.
支援情況
- SVG Tiny elements supported: defs, g, svg, circle, line, path, polygon, polyline, rect, text
- SVG Tiny elements not yet supported: desc, metadata, title, use, a, switch, ellipse, image, font, font-face, font-face-name, font-face-src, glyph, hkern, missing-glyph, animate, animateColor, animateMotion, animateTransform, mpath, set, foreignObject
- Additional elements supported: linearGradient, stop
- Text support is incomplete.
- The style attribute is supported.
安裝
1 | git clone git://git.netsurf-browser.org/libsvgtiny.git |
- 參考 疑問通訊
- 直接編譯 Netsurf 更快,參考 building instruction
資料結構
1 | struct svgtiny_shape { |
使用 Cairo
1 | /** |
討論
Libsvgtiny 無法編譯,無論是 official 還是 github 版本
- 改用 https://github.com/DavidPhillipOster/libsvgtiny
sed -i 's/-lxml2/-lxml2 -lm/g' Makefile && make
Libsvgtiny 有的可以成功顯示,有的部分顯示,有的則顯示失敗
(左、中、右圖分別對應 Image Viewer、Libsvgtiny with Cairo、Libsvgtiny with TWIN)
成功顯示
注意最右邊的圖顯示是正確的,因爲圓形和矩形沒有例如 fill: #000000
這樣的屬性,至於左邊兩個爲什麼會自動填黑很有趣。
部分成功顯示
- 都可顯示,但由於 Libsvgtiny 和 TWIN 的限制致使顯示有缺陷。中間的圖基本和原圖一樣,不過有條不明顯的黑線,可以修改
libsvgtiny.c
或刪除這條 path 多餘的stroke-width
屬性即可修正。最右除了 Libsvgtiny 自身的問題外,和 TWIN 也有關聯。
- Cairo 可成功顯示但 TWIN 不行(後已修復)
顯示失敗
- 其實修改 Libsvgtiny 後使用 Cairo 是可以大致顯示的,簡單說就是 Libsvgtiny 的 fill 邏輯出了問題,要麼都塗黑了如上圖所示,要麼如下圖沒把該塗黑的地方塗黑ORZ
- 使用 Netsurf 開啓老虎圖,直接笑出來了…
移植到 STM32F429 上的過程中,編譯鏈接又出問題了
1 | In file included from /usr/include/libxml2/libxml/parser.h:810:0, |
Jserv replied:
1 | git clone git://git.gnome.org/libxml2 |
libxml2 太龐大,無法放入 ARM 環境
Updates
2016/06/08
- 修復 Libsvgtiny 問題,顯示 tiger 黑圖(修改 Libsvgtiny 的 fill、stroke 可顯示不完全正確的 tiger 圖)
2016/06/11
- twin 接口問題,顯示 sonic 黑圖(使用 cairo 可正常顯示)
2016/06/12
- 修復 Libsvgtiny 縮放問題,在 STM32F429Discovery 上顯示成功