CN114637731A - Format conversion method and device based on SVG file - Google Patents

Format conversion method and device based on SVG file Download PDF

Info

Publication number
CN114637731A
CN114637731A CN202210332049.1A CN202210332049A CN114637731A CN 114637731 A CN114637731 A CN 114637731A CN 202210332049 A CN202210332049 A CN 202210332049A CN 114637731 A CN114637731 A CN 114637731A
Authority
CN
China
Prior art keywords
file
data structure
data
svg
attribute information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210332049.1A
Other languages
Chinese (zh)
Inventor
李文浩
武腾
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangdong Bozhilin Robot Co Ltd
Original Assignee
Guangdong Bozhilin Robot Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangdong Bozhilin Robot Co Ltd filed Critical Guangdong Bozhilin Robot Co Ltd
Priority to CN202210332049.1A priority Critical patent/CN114637731A/en
Publication of CN114637731A publication Critical patent/CN114637731A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/17Details of further file system functions
    • G06F16/178Techniques for file synchronisation in file systems
    • G06F16/1794Details of file format conversion

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Processing Or Creating Images (AREA)

Abstract

A format conversion method and device based on SVG files comprises the following steps: obtaining an SVG file; then, analyzing the file data of the SVG file to obtain element data information and element attribute information; the element attribute information includes at least shape attribute information and style setting attribute information; matching a predefined data structure corresponding to the element data information, and storing the element attribute information into the predefined data structure to obtain an application data structure; judging whether the application data structure has filling data according to the style setting attribute information; when the application data structure body contains filling data, carrying out triangularization processing on the application data structure body to obtain a GLTF file; when the application data structure body is not filled with data, the application data structure body is subjected to linearization processing to obtain a GLTF file, the SVG file can be converted into the GLTF file, the output quality of the graph is improved, the SVG file can be converted into the GLTF file, and the output quality of the graph is improved.

Description

Format conversion method and device based on SVG file
Technical Field
The application relates to the technical field of data processing, in particular to a format conversion method and device based on an SVG file.
Background
The SVG format is a format of an image file that can be directly used for designing a high-resolution Web graphic page, thereby providing high design convenience for a user. However, in practice, it is found that for some graphics with larger coordinates, the SVG format file cannot show more detailed contents, and the output quality of the graphics is affected.
Disclosure of Invention
The embodiment of the application aims to provide a format conversion method and device based on an SVG file, which can convert the SVG file into a GLTF file, so that the output quality of a graph is improved.
A first aspect of the embodiments of the present application provides a format conversion method based on an SVG file, including:
obtaining an SVG file;
analyzing the file data of the SVG file to obtain element data information and element attribute information; the element attribute information includes at least shape attribute information and style setting attribute information;
matching a predefined data structure corresponding to the element data information, and storing the element attribute information into the predefined data structure to obtain an application data structure;
judging whether the application data structure body has filling data or not according to the style setting attribute information;
when the application data structure body contains filling data, carrying out triangularization processing on the application data structure body to obtain a GLTF file;
and when the application data structure body has no filling data, performing linearization processing on the application data structure body to obtain a GLTF file.
In the above embodiment, the method may first obtain the SVG file, and then analyze the file data of the SVG file to obtain the element data information and the element attribute information; the element attribute information includes at least shape attribute information and style setting attribute information; then matching a predefined data structure corresponding to the element data information, and storing the element attribute information into the predefined data structure to obtain an application data structure; then, judging whether the application data structure has filling data according to the style setting attribute information; when the application data structure body contains filling data, triangularization processing is carried out on the application data structure body to obtain a GLTF file; and when the application data structure body has no filling data, performing linearization processing on the application data structure body to obtain the GLTF file. Therefore, by implementing the implementation mode, the SVG file can be converted into the GLTF file, so that the problem that the SVG can not open the graph with larger coordinates can be well solved, and the rendering capability is improved, so that the graph has high quality.
Further, the step of acquiring the SVG file includes:
acquiring file names of all files in a folder to be converted; the all files comprise SVG files and other files;
eliminating other file names of other files from the file names of all the files to obtain an SVG file name of the SVG file;
and reading the SVG file corresponding to the SVG file name.
Further, the element data information includes one or more of circle data, ellipse data, polyline data, polygon data, circular arc path data, and closed path data;
the predefined data structures include one or more of a circular data structure corresponding to the circular data, an elliptical data structure corresponding to the elliptical data, a multi-segment data structure corresponding to the multi-segment data, a polygon data structure corresponding to the polygon data, an arc path data structure corresponding to the arc path data, and a closed path data structure corresponding to the closed path data.
Further, after the step of matching the predefined data structure corresponding to the element data information and storing the element attribute information in the predefined data structure to obtain an application data structure, the method further includes:
extracting a plurality of graph nodes in the application data structure body;
according to a preset bounding box algorithm, constructing bounding boxes of the plurality of graph nodes to obtain an SVG graph range frame;
calculating the coordinate of the central point according to the SVG graphic range frame;
and generating a json file for expressing the size of the drawing frame range of the SVG file according to the SVG graphic range frame and the central point coordinate.
Further, the triangulating the application data structure to obtain the GLTF file includes:
extracting a plurality of graph nodes in the application data structure body;
triangularization processing is carried out on the plurality of graph nodes according to a computational geometry algorithm library to obtain triangular patch information;
and sequentially storing the triangular patch information into an access project of a GLTF file, storing the style setting attribute information into a material project of the GLTF file, setting a storage data format into a triangle type, and storing a preset conversion matrix into a node project of the GLTF file to obtain the GLTF file.
Further, the step of performing linearization processing on the application data structure to obtain the GLTF file includes:
extracting a plurality of graph nodes in the application data structure body;
carrying out coordinate transformation calculation on the plurality of graph nodes to obtain a plurality of coordinate data;
sequentially storing the coordinate data into an access project in a GLTF format, storing the style setting attribute information into a material project of the GLTF file, setting the stored data format into a line type, and storing a preset conversion matrix into a node project of the GLTF file to obtain the GLTF file.
A second aspect of the embodiments of the present application provides a format conversion device based on an SVG file, where the format conversion device based on an SVG file includes:
the acquisition unit is used for acquiring the SVG file;
the analysis unit is used for analyzing the file data of the SVG file to obtain element data information and element attribute information; the element attribute information includes at least shape attribute information and style setting attribute information;
the matching unit is used for matching a predefined data structure body corresponding to the element data information and storing the element attribute information into the predefined data structure body to obtain an application data structure body;
the judging unit is used for judging whether the application data structure body has filling data or not according to the style setting attribute information;
the processing unit is used for carrying out triangularization processing on the application data structure body to obtain a GLTF file when filling data exist in the application data structure body;
the processing unit is further configured to perform linearization processing on the application data structure body when no padding data exists in the application data structure body, so as to obtain a GLTF file.
In the above embodiment, the obtaining unit first obtains the SVG file; then, the analyzing unit analyzes the file data of the SVG file to obtain element data information and element attribute information; the element attribute information includes at least shape attribute information and style setting attribute information; the matching unit matches the predefined data structure corresponding to the element data information and stores the element attribute information into the predefined data structure to obtain an application data structure; then the judging unit judges whether the application data structure has filling data according to the style setting attribute information; when the application data structure body contains filling data, the processing unit conducts triangularization processing on the application data structure body to obtain a GLTF file; and when the application data structure body has no filling data, performing linearization processing on the application data structure body to obtain the GLTF file. Therefore, by implementing the embodiment, the SVG file can be converted into the GLTF file, so that the output quality of the graph is improved.
Further, the format conversion device based on the SVG file further includes:
an extraction unit, configured to extract a plurality of graph nodes in the application data structure;
the construction unit is used for constructing the bounding boxes of the plurality of graph nodes according to a preset bounding box algorithm to obtain an SVG graph range frame;
the computing unit is used for computing the coordinates of the central point according to the SVG graphic range frame;
and the generating unit is used for generating a json file for expressing the size of the drawing frame range of the SVG file according to the SVG graphic range frame and the central point coordinate.
A third aspect of the embodiments of the present application provides an electronic device, including a memory and a processor, where the memory is used for storing a computer program, and the processor runs the computer program to make the electronic device execute the SVG file-based format conversion method described in any one of the first aspect of the embodiments of the present application.
A fourth aspect of the embodiments of the present application provides a computer-readable storage medium, which stores computer program instructions, and when the computer program instructions are read and executed by a processor, the computer program instructions execute the format conversion method based on the SVG file according to any one of the first aspect of the embodiments of the present application.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are required to be used in the embodiments of the present application will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered as limiting the scope, and that those skilled in the art can also obtain other related drawings based on the drawings without inventive efforts.
Fig. 1 is a schematic flowchart of a format conversion method based on an SVG file according to an embodiment of the present application;
fig. 2 is a schematic structural diagram of a format conversion device based on an SVG file according to an embodiment of the present application;
fig. 3 is a schematic flowchart illustrating a triangulation processing method according to an embodiment of the present disclosure;
fig. 4 is a schematic flowchart illustrating an example of a format conversion method based on an SVG file according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be described below with reference to the drawings in the embodiments of the present application.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures. Meanwhile, in the description of the present application, the terms "first", "second", and the like are used only for distinguishing the description, and are not to be construed as indicating or implying relative importance.
Example 1
Referring to fig. 1, fig. 1 is a schematic flow chart of a format conversion method based on an SVG file according to this embodiment. The format conversion method based on the SVG file comprises the following steps:
s101, acquiring file names of all files in a folder to be converted; all files include SVG files and other files.
In this embodiment, the file in the SVG format is referred to as an SVG file.
In this embodiment, SVG is an image file format, is scalable vector graphics based on XML, can directly design a high-resolution Web graphics page, and a user can directly use a code to draw an image and can view the content of the image file through a browser at any time. Different elements in the SVG data format correspond to different shapes and different attributes can be used to define the size and position of the graphics. The shapes of the SVG mainly include graphic elements such as rectangle (rect), circle (circle), ellipse (ellipse), polyline (polyline), polygon (polygon), and path (path) elements, and these element types can describe various types of geometric primitives. The style setting attribute of the SVG mainly includes fill (fill) which is a color inside a setting object and stroke (stroke) which is a color of a setting object line.
In the present embodiment, SVG has advantages that it can be read and modified by multiple tools, smaller image size, and more compressible than JPEG and GIF. However, the SVG format is not supported by all browsers; meanwhile, for some graphics with larger coordinates, the SVG can not display detail contents. Therefore, the present embodiment describes a technical solution capable of solving the above-mentioned problems of defects, thereby enabling it to realize visual output.
And S102, eliminating other file names of other files from the file names of all the files to obtain the SVG file name of the SVG file.
In this embodiment, the method is to read all file names in the folder to be converted, then eliminate file names that are not in the svg format, and only keep the file names in the svg format. Through the method, the identification omission of the SVG file name in the traditional mode can be avoided, so that the SVG file can be accurately and comprehensively identified.
S103, reading the SVG file corresponding to the SVG file name.
S104, analyzing the file data of the SVG file to obtain element data information and element attribute information; the element attribute information includes at least shape attribute information and style setting attribute information.
In this embodiment, the element data information includes one or more of circle data, ellipse data, polyline data, polygon data, circular arc path data, and closed path data, which is not limited in this embodiment of the present application.
In this embodiment, the predefined data structure includes one or more of a circular data structure corresponding to circular data, an elliptical data structure corresponding to elliptical data, a multi-segment data structure corresponding to multi-segment data, a polygon data structure corresponding to polygon data, an arc path data structure corresponding to arc path data, and a closed path data structure corresponding to closed path data, which is not limited in this embodiment.
In the embodiment, the method can read the file data content according to the SVG file name, and then analyze and read the SVG format file data by calling the XML parser library to obtain all element data information (which can be understood as SVG tags) and style setting attribute information (which can be understood as attributes corresponding to the tags).
In this embodiment, the method may classify and store the circular path (circle), the elliptical path (ellipse), the polyline (polyline), the polygon (polygon), the circular path (path-a), and the closed path (path-Z).
And S105, matching the predefined data structure corresponding to the element data information, and storing the element attribute information into the predefined data structure to obtain an application data structure.
In this embodiment, when the element data information is a POLYLINE (POLYLINE), the method may store the shape attribute information (i.e., X, Y coordinate values of the point) and the style setting attribute information (i.e., data such as fill (fill) and stroke (stroke)) by using a predefined POLYLINE structure.
In this embodiment, when the element data information is a CIRCLE (CIRCLE), the method may store shape attribute information (i.e., a coordinate value of the center X, Y and a numerical value of the radius r) and style setting attribute information (i.e., data such as fill (fill) and stroke (stroke)) through a predefined CIRCLE structure.
In this embodiment, when the element data information is an ELLIPSE (ELLIPSE), the method stores shape attribute information (i.e., a coordinate value of a center X, Y, values of a major axis ry and a minor axis rx, and a self-rotation angle value) and style setting attribute information (i.e., data such as fill (fill) and stroke (stroke)) through a predefined elipse structure.
In this embodiment, when the element data information is a POLYGON (POLYGON), the method stores shape attribute information (i.e., X, Y coordinate values of a point) and style setting attribute information (i.e., data such as fill (fill) and stroke (stroke)) by a predefined pogon structure.
In this embodiment, the element data information is an arc path (when path-a is used, the method stores shape attribute information (i.e., values of a long axis radius ry and a short axis radius rx, an x axis rotation angle, whether an arc is greater than 180 °, whether an arc direction is clockwise or counterclockwise, and an arc end coordinate X, Y) and style setting attribute information (i.e., data such as fill (fill) and stroke (stroke)) by using a predefined PATHA structure.
In this embodiment, when the element data information is a closed path (path-Z), the method stores shape attribute information (i.e., X, Y coordinate values of a point) and style setting attribute information (i.e., data such as fill (file) and stroke (stroke)) by using a predefined path Z structure.
As an optional implementation manner, after the step of matching the predefined data structure corresponding to the element data information and storing the element attribute information into the predefined data structure to obtain the application data structure, the method further includes:
extracting a plurality of graph nodes in an application data structure body;
constructing bounding boxes of a plurality of graph nodes according to a preset bounding box algorithm to obtain an SVG graph range frame;
calculating the coordinate of the central point according to the SVG graphic range frame;
and generating a json file for representing the frame range size of the SVG file according to the SVG graphic range frame and the center point coordinates.
In this embodiment, the graph nodes stored in the multi-segment line, polygon, and closed path structure are directly extracted and stored in all the point sets.
In this embodiment, the data in the circular structure needs to be converted. Specifically, according to the parametric equation of a circle: and X is a + r cos theta, Y is b + r sin theta, and coordinates of the graph nodes of the circular structural body can be obtained, wherein a represents a circle center X coordinate value, b represents a circle center Y coordinate value, r represents a circle radius value, and theta represents an included angle between any point on the circle and the positive direction of the X axis. The circle is divided into 72 parts by setting 5 degrees as a division included angle, theta is 5 x i, and i is more than or equal to 0 and less than or equal to 72. The coordinates of all points on the circle are thus taken and stored in all point sets.
In this embodiment, data in the elliptical structure and the circular arc structure need to be converted. According to the parametric equation of the ellipse:
x=a+cosα*(rx*cosθ)-sinα*(ry*sinθ),y=b+sinα*(rx*cosθ)+cosα*(ry*sinθ),
coordinates of points of the ellipse can be obtained, wherein a represents a coordinate value of a circle center X, b represents a coordinate value of a circle center Y, rx represents a minor axis radius, ry represents a major axis radius, alpha represents a rotation angle of the ellipse, and theta represents an included angle between any point on the ellipse and the positive direction of the X axis. The ellipse is divided into 72 parts by setting 5 degrees as a division included angle, theta is 5 x i, and i is more than or equal to 0 and less than or equal to 72. The coordinates of all points on the ellipse are thus obtained and stored in all point sets.
In this embodiment, after all the point sets are stored, the method may construct bounding boxes of all the point sets through a bounding box algorithm, obtain a whole SVG graphics range frame, determine Xmin, Xmax, Ymin, and Ymax values of the graphics frame, and calculate coordinate values of the central point at the same time.
In this embodiment, after the method acquires the graphic frame data of the whole SVG file, the Xmin, Xmax, Ymin, and Ymax values therein may be converted to obtain a json file, and the json file is output. So that the SVG file can display the frame range size through the json file.
S106, judging whether the application data structure has filling data according to the style setting attribute information, and if so, executing the step S107 to the step S109; if not, step S110 is executed.
And S107, when the application data structure body contains filling data, extracting a plurality of graph nodes in the application data structure body.
And S108, triangularizing the plurality of graph nodes according to the computational geometry algorithm library to obtain triangular patch information.
S109, sequentially storing the triangular patch information into an access project of the GLTF file, storing the style setting attribute information into a material project of the GLTF file, setting the storage data format into a triangle type, storing a preset conversion matrix into a node project of the GLTF file to obtain the GLTF file, and ending the process.
And S110, when the application data structure body has no filling data, performing linearization processing on the application data structure body to obtain a GLTF file.
Referring to fig. 3, fig. 3 is a schematic flow chart illustrating a triangulation processing method. Specifically, the method can perform judgment according to style setting attribute information in a plurality of data structures, perform triangulation processing on the data structure with filling information to output GLTF, and output GLTF by a data structure without filling information in a linear structure. The method can judge filling (fill) attribute values in the style setting attributes of various data structure bodies, if the data structure bodies with the filling attributes need to triangulate corresponding graphs and then output the graphs, and if the data structure bodies without the filling attributes are directly converted into linear data to output the linear data.
On the one hand, for the data structure without filling attribute, the method can reconstruct the data in the structure into the data of the points and output the data (the reconstruction process is the same as the process of acquiring the coordinates of all the point sets in the above steps). Meanwhile, in order to solve the problem of viewport offset caused by overlarge coordinate values of the points, coordinates of all the points are uniformly translated by a distance from the center point to the origin of the frame of the graphic range, namely, the coordinates of all the points subtract a coordinate value of the center point. And sequentially storing the data of all the points in an access item in a GLTF format, storing a style setting attribute in a material item, and generating a linear data GLTF file, wherein the stored data format is a line type.
On the other hand, for the data structure with the fill attribute, the method may reconstruct the data in the structure into the data of the points and output the data (the reconstruction process is the same as the process of acquiring the coordinates of all the point sets in the above steps). And then carrying out triangularization processing on the filled structure body by utilizing a CGAL (computational geometry algorithm library), generating triangular patch information, sequentially storing the triangular patch information in an access project in a GLTF format, storing a style setting attribute in a material project, storing a data format in a triangle type, and generating a triangular data GLTF file.
In this embodiment, since the viewport position needs to be adjusted, the method needs to translate the coordinates of all points. Therefore, in order to obtain the coordinates of the real points, the method sets the conversion matrix in the node item in the GLTF format, so as to promote the accurate generation of the GLTF file.
In this embodiment, the GLTF is essentially a graphical language transport format of a JSON structure, and at present, almost every framework supports the visual output of the GLTF format. Specifically, the GLTF format optimizes the reading efficiency of an application program, reduces the running time of a rendering model, minimizes 3D file resources, and supports the storage of information such as the geometry, materials, animation scenes and the like of the 3D model, so that the problem that the SVG cannot open a graph with larger coordinates can be well solved, and the rendering capability is improved to enable the graph to be output with high quality.
As an optional implementation manner, the step of performing linearization processing on the application data structure to obtain the GLTF file includes:
extracting a plurality of graph nodes in an application data structure body;
carrying out coordinate transformation calculation on the plurality of graph nodes to obtain a plurality of coordinate data;
the method comprises the steps of sequentially storing a plurality of coordinate data into an access project in a GLTF format, storing style setting attribute information into a material project of a GLTF file, setting the stored data format into a line type, and storing a preset conversion matrix into a node project of the GLTF file to obtain the GLTF file.
Referring to fig. 4, fig. 4 is a schematic flow chart illustrating an example format conversion method based on an SVG file. As can be seen from fig. 4, the method can preferentially read and store all SVG file names in one folder, and then recognize SVG files in the SVG format; then, analyzing the SVG format data to acquire data information and attribute information corresponding to different elements; according to the data information and the attribute information, the method can select different predefined data structure bodies to determine whether filling data (namely filling information) exists and acquire all point sets in the image; then, the method can select a mode for generating the GLTF file based on the filling information and generate the GLTF file; meanwhile, the method can also determine the graphic frame data of the SVG file based on all the point sets and then output the graphic frame data in the form of a json document.
Therefore, by implementing the implementation mode, the SVG file can be subjected to adaptive format conversion, so that the SVG file can be used in different places conveniently, and the output quality of the graphic content in the SVG file is improved.
In this embodiment, the execution subject of the method may be a computing device such as a computer and a server, and is not limited in this embodiment.
In this embodiment, an execution subject of the method may also be an intelligent device such as a smart phone and a tablet computer, which is not limited in this embodiment.
As can be seen, by implementing the format conversion method based on the SVG file described in this embodiment, a large number of GLTF format files corresponding to the SVG file can be generated at a time; meanwhile, the method can also triangulate the closed graph with the filling information in the SVG file, and convert the closed graph into a triangular surface format in the GLTF for visual output; then, the method can also uniformly convert the SVG linear information and the filled graphic information into GLTF visual output; and finally, the method can also calculate the input graphic range frame of the SVG and convert the graphic range frame into a json file for output.
Example 2
Referring to fig. 2, fig. 2 is a schematic structural diagram of a format conversion device based on an SVG file according to this embodiment. As shown in fig. 2, the format conversion device based on the SVG file includes:
an obtaining unit 210, configured to obtain an SVG file;
the parsing unit 220 is configured to parse file data of the SVG file to obtain element data information and element attribute information; the element attribute information includes at least shape attribute information and style setting attribute information;
the matching unit 230 is configured to match the predefined data structure corresponding to the element data information, and store the element attribute information in the predefined data structure to obtain an application data structure;
a judging unit 240, configured to judge whether there is padding data in the application data structure according to the style setting attribute information;
the processing unit 250 is used for performing triangulation processing on the application data structure to obtain a GLTF file when the application data structure contains filling data;
and the processing unit 250 is further configured to perform linearization processing on the application data structure to obtain a GLTF file when there is no padding data in the application data structure.
As an optional implementation manner, the format conversion apparatus based on the SVG file further includes:
an extracting unit 260 for extracting a plurality of graph nodes in the application data structure;
the building unit 270 is configured to build bounding boxes of the plurality of graph nodes according to a preset bounding box algorithm to obtain an SVG graph range frame;
the calculating unit 280 is used for calculating the coordinates of the central point according to the SVG graphic range frame;
and a generating unit 290, configured to generate a json file indicating a frame range size of the SVG file according to the SVG graphic range frame and the center point coordinates.
In the embodiment of the present application, the element data information includes one or more of circle data, ellipse data, polyline data, polygon data, circular arc path data, and closed path data, and the embodiment of the present application is not limited thereto.
In this embodiment, the predefined data structures include one or more of a circular data structure corresponding to circular data, an elliptical data structure corresponding to elliptical data, a multi-segment data structure corresponding to multi-segment data, a polygon data structure corresponding to polygon data, an arc path data structure corresponding to arc path data, and a closed path data structure corresponding to closed path data, which is not limited in this embodiment.
As an optional implementation, the obtaining unit 210 includes:
an obtaining subunit 211, configured to obtain file names of all files in the folder to be converted; all files include SVG files and other files;
the removing subunit 212 is configured to remove other file names of other files from the file names of all the files to obtain an SVG file name of the SVG file;
and the reading subunit 213 is configured to read the SVG file corresponding to the SVG file name.
As an alternative embodiment, the processing unit 250 includes:
an extraction subunit 251, configured to extract a plurality of graph nodes in the application data structure;
the processing subunit 252 is configured to perform triangularization processing on the multiple graph nodes according to the computational geometry algorithm library to obtain triangular patch information;
the storage subunit 253 is configured to sequentially store the triangle patch information into an access item of the GLTF file, store the style setting attribute information into a material item of the GLTF file, set the storage data format to a triangle type, and store a preset conversion matrix into a node item of the GLTF file to obtain the GLTF file.
As an optional implementation, the extracting subunit 251 is further configured to, when there is no padding data in the application data structure, extract a plurality of graph nodes in the application data structure;
the processing unit 250 further includes:
a calculation subunit 254, configured to perform coordinate transformation calculation on the multiple graph nodes to obtain multiple coordinate data;
the storage subunit 253 is further configured to sequentially store the plurality of coordinate data into an access item in the GLTF format, store the style setting attribute information into a material item of the GLTF file, set the storage data format into a line type, and store the preset conversion matrix into a node item of the GLTF file, so as to obtain the GLTF file.
In the embodiment of the present application, for the explanation of the format conversion device based on the SVG file, reference may be made to the description in embodiment 1, and details are not repeated in this embodiment.
As can be seen, the format conversion device based on the SVG file described in this embodiment can generate a large number of GLTF format files corresponding to the SVG file at a time; meanwhile, the method can also triangulate the closed graph with the filling information in the SVG file, and convert the closed graph into a triangular surface format in the GLTF for visual output; then, the method can also uniformly convert the SVG linear information and the filled graphic information into GLTF visual output; and finally, the method can also calculate the input graphic range frame of the SVG and convert the graphic range frame into a json file for output.
An embodiment of the present application provides an electronic device, including a memory and a processor, where the memory is used to store a computer program, and the processor runs the computer program to make the electronic device execute the format conversion method based on the SVG file in embodiment 1 of the present application.
An embodiment of the present application provides a computer-readable storage medium, which stores computer program instructions, and when the computer program instructions are read and executed by a processor, the computer program instructions execute the format conversion method based on the SVG file in embodiment 1 of the present application.
It should be understood that XML is used to represent the extensible markup language, a subset of the standard generalized markup language, a markup language for making electronic documents structured;
the predefined data structure body is used for representing a predefined data type and is composed of a group of different member data, and the members can have different data types;
the bounding box is an algorithm for solving the optimal bounding space of the discrete point set, and a geometric body with a slightly larger volume and simple characteristics is used for approximately replacing a complex set object.
At the same time, it should also be understood that:
access entry for GLTF: accessing an abstract data source of any data in the GLTF, and storing actual binary data by referring to a data storage body of bufferView;
material project of GLTF: the GLTF is used for defining parameters of object appearance and mainly comprises data such as color, material, texture and the like;
line type of GLTF: the stored data can generate lines according to the distribution of points when being rendered, and the construction of linear information such as single lines, continuous lines, closed lines and the like is completed;
triangle type of GLTF: when the stored data is rendered, the graphics are generated according to the form of a triangular surface, namely, all the graphics are divided into the triangular surfaces to be constructed;
node entry of GLTF: a node in the GLTF scene graph, which can contain rotation or translation and other transformations, is mainly used for describing the transformation process of the table;
CGAL computational geometry library: the method is widely applied to an open-source C + + language efficient algorithm library in the related field of geometric computing.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented in other ways. The apparatus embodiments described above are merely illustrative, and for example, the flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In addition, functional modules in the embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
The functions, if implemented in the form of software functional modules and sold or used as a stand-alone product, may be stored in a computer-readable storage medium. Based on such understanding, the technical solution of the present application or portions thereof that substantially contribute to the prior art may be embodied in the form of a software product stored in a storage medium and including instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above description is only an example of the present application and is not intended to limit the scope of the present application, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, improvement and the like made within the spirit and principle of the present application shall be included in the protection scope of the present application. It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
The above description is only for the specific embodiments of the present application, but the scope of the present application is not limited thereto, and any person skilled in the art can easily think of the changes or substitutions within the technical scope of the present application, and shall be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
It should be noted that, in this document, relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.

Claims (10)

1. A format conversion method based on an SVG file is characterized by comprising the following steps:
obtaining an SVG file;
analyzing the file data of the SVG file to obtain element data information and element attribute information; the element attribute information includes at least shape attribute information and style setting attribute information;
matching a predefined data structure corresponding to the element data information, and storing the element attribute information into the predefined data structure to obtain an application data structure;
judging whether the application data structure body has filling data or not according to the style setting attribute information;
when the application data structure body contains filling data, carrying out triangularization processing on the application data structure body to obtain a GLTF file;
and when the application data structure body has no filling data, performing linearization processing on the application data structure body to obtain a GLTF file.
2. The SVG file-based format conversion method according to claim 1, wherein said step of obtaining an SVG file comprises:
acquiring file names of all files in a folder to be converted; the all files comprise SVG files and other files;
eliminating other file names of other files from the file names of all the files to obtain the SVG file name of the SVG file;
and reading the SVG file corresponding to the SVG file name.
3. The SVG file-based format conversion method according to claim 1, wherein the element data information includes one or more of circle data, ellipse data, polyline data, polygon data, circular arc path data and closed path data;
the predefined data structures include one or more of a circular data structure corresponding to the circular data, an elliptical data structure corresponding to the elliptical data, a multi-segment data structure corresponding to the multi-segment data, a polygon data structure corresponding to the polygon data, an arc path data structure corresponding to the arc path data, and a closed path data structure corresponding to the closed path data.
4. The SVG file-based format conversion method of claim 1, wherein after the step of matching the predefined data structure corresponding to the elemental data information and storing the elemental attribute information into the predefined data structure to obtain an application data structure, the method further comprises:
extracting a plurality of graph nodes in the application data structure body;
according to a preset bounding box algorithm, constructing bounding boxes of the plurality of graph nodes to obtain an SVG graph range frame;
calculating the coordinate of the central point according to the SVG graphic range frame;
and generating a json file for expressing the size of the drawing frame range of the SVG file according to the SVG graphic range frame and the central point coordinate.
5. The SVG file-based format conversion method according to claim 1, wherein the triangulating the application data structure to obtain a GLTF file comprises:
extracting a plurality of graph nodes in the application data structure body;
triangularization processing is carried out on the plurality of graph nodes according to a computational geometry algorithm library to obtain triangular patch information;
and sequentially storing the triangular patch information into an access project of a GLTF file, storing the style setting attribute information into a material project of the GLTF file, setting a storage data format into a triangle type, and storing a preset conversion matrix into a node project of the GLTF file to obtain the GLTF file.
6. The SVG file-based format conversion method according to claim 1, wherein the step of linearizing the application data structure to obtain the GLTF file comprises:
extracting a plurality of graph nodes in the application data structure body;
carrying out coordinate transformation calculation on the plurality of graph nodes to obtain a plurality of coordinate data;
sequentially storing the coordinate data into an access project in a GLTF format, storing the style setting attribute information into a material project of the GLTF file, setting the stored data format into a line type, and storing a preset conversion matrix into a node project of the GLTF file to obtain the GLTF file.
7. A format conversion apparatus based on an SVG file, comprising:
the acquisition unit is used for acquiring the SVG file;
the analysis unit is used for analyzing the file data of the SVG file to obtain element data information and element attribute information; the element attribute information includes at least shape attribute information and style setting attribute information;
the matching unit is used for matching a predefined data structure body corresponding to the element data information and storing the element attribute information into the predefined data structure body to obtain an application data structure body;
the judging unit is used for judging whether the application data structure body has filling data or not according to the style setting attribute information;
the processing unit is used for carrying out triangularization processing on the application data structure body to obtain a GLTF file when filling data exist in the application data structure body;
the processing unit is further configured to perform linearization processing on the application data structure body when no padding data exists in the application data structure body, so as to obtain a GLTF file.
8. The SVG file-based format conversion device of claim 7, wherein the SVG file-based format conversion device further comprises:
an extraction unit, configured to extract a plurality of graph nodes in the application data structure;
the construction unit is used for constructing the bounding boxes of the plurality of graph nodes according to a preset bounding box algorithm to obtain an SVG graph range frame;
the computing unit is used for computing the coordinates of the central point according to the SVG graphic range frame;
and the generating unit is used for generating a json file for expressing the size of the drawing frame range of the SVG file according to the SVG graphic range frame and the central point coordinate.
9. An electronic device, characterized in that the electronic device comprises a memory for storing a computer program and a processor for executing the computer program to cause the electronic device to execute the SVG file-based format conversion method of any one of claims 1 to 6.
10. A readable storage medium, characterized in that it stores therein computer program instructions which, when read and executed by a processor, execute the SVG file-based format conversion method of any one of claims 1 to 6.
CN202210332049.1A 2022-03-30 2022-03-30 Format conversion method and device based on SVG file Pending CN114637731A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210332049.1A CN114637731A (en) 2022-03-30 2022-03-30 Format conversion method and device based on SVG file

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210332049.1A CN114637731A (en) 2022-03-30 2022-03-30 Format conversion method and device based on SVG file

Publications (1)

Publication Number Publication Date
CN114637731A true CN114637731A (en) 2022-06-17

Family

ID=81952617

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210332049.1A Pending CN114637731A (en) 2022-03-30 2022-03-30 Format conversion method and device based on SVG file

Country Status (1)

Country Link
CN (1) CN114637731A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115599491A (en) * 2022-12-14 2023-01-13 西安纽扣软件科技有限公司(Cn) SVG vector diagram display method, device, equipment and storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115599491A (en) * 2022-12-14 2023-01-13 西安纽扣软件科技有限公司(Cn) SVG vector diagram display method, device, equipment and storage medium

Similar Documents

Publication Publication Date Title
Roveri et al. Pointpronets: Consolidation of point clouds with convolutional neural networks
US9484006B2 (en) Manipulation of textual content data for layered presentation
Speciale et al. A symmetry prior for convex variational 3d reconstruction
Wong et al. Segmentation of additive manufacturing defects using U-net
CN109684005B (en) Method and device for determining similarity of components in graphical interface
CN109376698B (en) Face modeling method and device, electronic equipment, storage medium and product
CN114417064A (en) Data processing method and device, computer equipment and storage medium
CN115062362B (en) Paper box cutting board development method and device based on FreeCAP kernel and related equipment
Sheng et al. A lightweight surface reconstruction method for online 3D scanning point cloud data oriented toward 3D printing
CN114637731A (en) Format conversion method and device based on SVG file
CN114005125A (en) Table identification method and device, computer equipment and storage medium
CN108241861A (en) A kind of data visualization method and equipment
Popov et al. Efficient contouring of functionally represented objects for additive manufacturing
Guo et al. Generating Artistic Portraits from Face Photos with Feature Disentanglement and Reconstruction
Béarzi et al. Wavejets: A local frequency framework for shape details amplification
US20230109732A1 (en) Generation of stylized drawing of three-dimensional shapes using neural networks
CN116188660B (en) Point cloud data processing method and related device based on stream rendering
CN116610304A (en) Page code generation method, device, equipment and storage medium
Shardt et al. Surface parameterization of nonsimply connected planar Bézier regions
White et al. A fully automated high-performance image registration workflow to support precision geolocation for imagery collected by airborne and spaceborne sensors
Antoniou et al. The potential of XML encoding in geomatics converting raster images to XML and SVG
Homburg et al. 3D data derivatives of the Haft Tappeh processing pipeline
Brown et al. Making Japenese ukiyo-e art 3D in real-time
Feng et al. Part2Point: A Part-Oriented Point Cloud Reconstruction Framework
Comes The preservation and long-term use of 3D digitized cultural heritage assets

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination