Chromium HTML5 <svg>对应c++接口说明

一、SVG:可缩放矢量图形

开始学习 SVG

可缩放矢量图形Scalable Vector Graphics,SVG )基于 XML 标记语言,用于描述二维的矢量图形

作为一个基于文本的开放网络标准,SVG 能够优雅而简洁地渲染不同大小的图形,并和 CSSDOMJavaScriptSMIL 等其他网络标准无缝衔接。本质上,SVG 相对于图像,就好比 HTML 相对于文本。

SVG 图像及其相关行为被定义于 XML 文本文件之中,这意味着可以对它们进行搜索、索引、编写脚本以及压缩。此外,这也意味着可以使用任何文本编辑器和绘图软件来创建和编辑它们。

和传统的点阵图像模式(如 JPEGPNG)不同的是,SVG 格式提供的是矢量图,这意味着它的图像能够被无限放大而不失真或降低质量,并且可以方便地修改内容,无需图形编辑器。通过使用合适的库进行配合,SVG 文件甚至可以随时进行本地化。

SVG 是由万维网联盟(W3C)自 1999 年开始开发的开放标准。

其他内容请查阅 SVG 教程

文档

SVG 元素参考

了解每一种 SVG 元素的细节。

SVG 属性参考

了解每一种 SVG 属性的细节。

SVG DOM 接口参考

了解有关 SVG DOM API 的全部细节。

SVG:可缩放矢量图形 | MDN (mozilla.org)

前端测试用例:

html 复制代码
<!DOCTYPE html>
<html>
<body>

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
   <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red" />
   <line x1="0" y1="80" x2="100" y2="20" stroke="black" />
</svg> 
 
</body>
</html>

二、<svg>对应c++接口定义:

1、<svg>对应svg_tag_names.json5

third_party\blink\renderer\core\svg\svg_tag_names.json5 文件里面定义了所有对象元素:

cpp 复制代码
{
  metadata: {
    namespace: "SVG",
    namespaceURI: "http://www.w3.org/2000/svg",
    fallbackInterfaceName: "SVGUnknownElement",
    fallbackJSInterfaceName: "SVGElement",
    export: "CORE_EXPORT",
  },

  data: [
    "a",
    {
      name: "animate",
      noTypeHelpers: true,
    },
    {
      name: "animateColor",
      JSInterfaceName: "SVGElement",
      interfaceName: "SVGUnknownElement",
      noConstructor: true,
    },
    "animateMotion",
    "animateTransform",
    "set",
    "circle",
    "clipPath",
    "defs",
    "desc",
    "ellipse",
    "feBlend",
    "feColorMatrix",
    "feComponentTransfer",
    "feComposite",
    "feConvolveMatrix",
    "feDiffuseLighting",
    "feDisplacementMap",
    "feDistantLight",
    "feDropShadow",
    "feFlood",
    "feFuncA",
    "feFuncB",
    "feFuncG",
    "feFuncR",
    "feGaussianBlur",
    "feImage",
    "feMerge",
    "feMergeNode",
    "feMorphology",
    "feOffset",
    "fePointLight",
    "feSpecularLighting",
    "feSpotLight",
    "feTile",
    "feTurbulence",
    "filter",
    "foreignObject",
    "g",
    "image",
    "line",
    "linearGradient",
    "marker",
    "mask",
    "metadata",
    {
      name: "mpath",
      interfaceName: "SVGMPathElement",
    },
    "path",
    "pattern",
    "polygon",
    "polyline",
    "radialGradient",
    "rect",
    {
      name: "script",
      constructorNeedsCreateElementFlags: true,
    },
    "stop",
    {
      name: "style",
      constructorNeedsCreateElementFlags: true,
    },
    {
      name: "svg",
      interfaceName: "SVGSVGElement",
    },
    "switch",
    "symbol",
    "text",
    "textPath",
    "title",
    {
      name: "tspan",
      interfaceName: "SVGTSpanElement",
    },
    "use",
    "view",
  ],
}

2、元素对应都在以下两个文件下 包含"svg"关键字的。

src\third_party\blink\renderer\core\svg

src\out\Debug\gen\third_party\blink\renderer\bindings\core\v8

三、本文以<line>和<circle>为例:

1、<line>接口定义:

third_party\blink\renderer\core\svg\svg_line_element.idl

cpp 复制代码
// https://svgwg.org/svg2-draft/shapes.html#InterfaceSVGLineElement

[Exposed=Window]
interface SVGLineElement : SVGGeometryElement {
    [MeasureAs=SVG1DOMShape] readonly attribute SVGAnimatedLength x1;
    [MeasureAs=SVG1DOMShape] readonly attribute SVGAnimatedLength y1;
    [MeasureAs=SVG1DOMShape] readonly attribute SVGAnimatedLength x2;
    [MeasureAs=SVG1DOMShape] readonly attribute SVGAnimatedLength y2;
};

third_party\blink\renderer\core\svg\svg_line_element.h

third_party\blink\renderer\core\svg\svg_line_element.cc

out\Debug\gen\third_party\blink\renderer\bindings\core\v8\v8_svg_line_element.h

out\Debug\gen\third_party\blink\renderer\bindings\core\v8\v8_svg_line_element.cc

2、<circle>接口定义:

third_party\blink\renderer\core\svg\svg_circle_element.idl

cpp 复制代码
// https://svgwg.org/svg2-draft/shapes.html#InterfaceSVGCircleElement

[Exposed=Window]
interface SVGCircleElement : SVGGeometryElement {
    [MeasureAs=SVG1DOMShape] readonly attribute SVGAnimatedLength cx;
    [MeasureAs=SVG1DOMShape] readonly attribute SVGAnimatedLength cy;
    [MeasureAs=SVG1DOMShape] readonly attribute SVGAnimatedLength r;
};

third_party\blink\renderer\core\svg\svg_circle_element.h

third_party\blink\renderer\core\svg\svg_circle_element.cc

out\Debug\gen\third_party\blink\renderer\bindings\core\v8\v8_svg_circle_element.h

out\Debug\gen\third_party\blink\renderer\bindings\core\v8\v8_svg_circle_element.cc

相关推荐
GISer_Jing6 分钟前
[总结篇]个人网站
前端·javascript
疯狂的沙粒27 分钟前
在web-view 加载的本地及远程HTML中调用uniapp的API及网页和vue页面是如何通讯的?
前端·uni-app·html
小妖66631 分钟前
html 滚动条滚动过快会留下边框线
前端·html
KyollBM36 分钟前
【CF】Day75——CF (Div. 2) B (数学 + 贪心) + CF 882 (Div. 2) C (01Trie | 区间最大异或和)
c语言·c++·算法
heroboyluck1 小时前
Svelte 核心语法详解:Vue/React 开发者如何快速上手?
前端·svelte
海的诗篇_1 小时前
前端开发面试题总结-JavaScript篇(二)
开发语言·前端·javascript·typescript
feiyangqingyun1 小时前
Qt/C++开发监控GB28181系统/取流协议/同时支持udp/tcp被动/tcp主动
c++·qt·udp·gb28181
CV点灯大师1 小时前
C++算法训练营 Day10 栈与队列(1)
c++·redis·算法
琹箐1 小时前
ant-design4.xx实现数字输入框; 某些输入法数字需要连续输入两次才显示
前端·javascript·anti-design-vue
程序员-小李1 小时前
VuePress完美整合Toast消息提示
前端·javascript·vue.js