Path segmentation and processing method and device for single-layer SVG image, equipment and medium
By analyzing the grouping hierarchical information of SVG files and generating independent sub-path data, the shortcomings of single-layer content path data processing in the prior art are solved, and efficient distinction between single-layer and multi-layer and flexible operation of path data are realized, which improves the efficiency and flexibility of SVG image processing.
Patent Information
- Application Number
- CN202411972195.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-05-16
AI Technical Summary
When processing SVG files, it is difficult to effectively distinguish the file structures of single-layer and multi-layers, and there are shortcomings in the extraction and processing of path data of single-layer content, so it is impossible to quickly convert geometric figures into path objects and perform independent path data extraction, which limits the application of path data in operations such as segmentation and reorganization.
By loading the SVG file and displaying the image content in the graphical operation interface, parsing the grouping hierarchy information of the SVG file, it is determined to be a single layer or multiple layers. When it is detected as a single layer, the child elements in the single layer are type-identified and processed to generate independent subpath data. A sub-SVG image is generated based on the sub-path data, and displayed and selected in the graphical operation interface. The sub-path data corresponding to the selected sub-SVG image is recombined, an updated SVG image is generated, and processing or rendering operations are performed.
It realizes efficient distinction between single layer and multiple layer, and combines the generation and reorganization of sub-path data, which can meet users' needs for display, select and process local graphic content, and improves the efficiency and flexibility of SVG image processing.
Smart Images

Figure CN120014113A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer graphics processing, and in particular to a path segmentation and processing method, device, equipment and storage medium for a single-layer SVG image. Background Art
[0002] SVG (Scale Vector Graphics) files are a vector graphics standard that are widely used in graphics editing and manufacturing due to their efficient graphics representation capabilities and good scalability. However, when processing SVG files, the existing technology has limited capabilities for parsing file loading and grouping hierarchical information, and it is difficult to effectively distinguish between single-layer and multi-layer file structures, which brings inconvenience to further graphics operations and optimization processing.
[0003] In the process of graphics processing, the existing technology has deficiencies in the extraction and processing of path data of single layer content. In particular, in the operation of path objects (Path) and geometric figures, the existing methods lack a unified processing mechanism and cannot quickly convert geometric figures into path objects and further extract independent path data, thus limiting the application of path data in operations such as segmentation and reorganization.
[0004] In addition, the existing technology also lacks effective support for displaying and selecting the generated image content. It is difficult for users to intuitively display and hide sub-images through the graphical interface, and to reorganize or process the selected images. Especially when generating the final SVG image or performing graphics rendering and processing operations, the existing methods are inefficient and cannot meet the diverse graphics application requirements. Summary of the invention
[0005] The main purpose of the present invention is to provide a path segmentation and processing method, device, equipment and storage medium for a single-layer SVG image, aiming to solve the technical problem that the prior art lacks a unified processing method for sub-element type identification, path data generation and reorganization of single-layer content when processing SVG files, and cannot efficiently support the segmentation, selection or processing operations of graphic content.
[0006] To achieve the above object, the present invention provides a path segmentation and processing method for a single-layer SVG image, comprising:
[0007] Loading an SVG file and displaying the image content of the SVG file in a graphical operation interface;
[0008] Parsing the grouping level information of the SVG file to determine whether the SVG file is a single layer or multiple layers;
[0009] When the SVG file is a single layer, the sub-elements in the single layer are identified and processed to generate independent sub-path data;
[0010] Generate a sub-SVG image based on the sub-path data, display and select it in a graphical operation interface, and reassemble the sub-path data corresponding to the selected sub-SVG image to generate an updated SVG image;
[0011] A processing or rendering operation is performed on the updated SVG image.
[0012] Furthermore, to achieve the above-mentioned purpose, the present invention provides a path segmentation and processing device for a single-layer SVG image, comprising:
[0013] A file loading and visualization module, used to load an SVG file and display the image content of the SVG file in a graphical operation interface;
[0014] A layer parsing module, used to parse the grouping level information of the SVG file and determine whether the SVG file is a single layer or multiple layers;
[0015] A path parsing and data generation module, for, when the SVG file is a single layer, performing type identification and processing on sub-elements in the single layer, and generating independent sub-path data;
[0016] A sub-image generation module, for generating a sub-SVG image based on the sub-path data, and displaying and selecting the sub-SVG image in a graphical operation interface, and recombining the sub-path data corresponding to the selected sub-SVG image to generate an updated SVG image;
[0017] The graphics processing and rendering module is used to perform processing or rendering operations on the updated SVG image.
[0018] Furthermore, to achieve the above-mentioned purpose, the present invention also provides a computer device, which includes a memory, a processor, and a path segmentation and processing program for a single-layer SVG image stored in the memory and runnable on the processor, wherein the path segmentation and processing program for a single-layer SVG image, when executed by the processor, implements the steps of the path segmentation and processing method for a single-layer SVG image as described above.
[0019] Furthermore, to achieve the above-mentioned purpose, the present invention also provides a computer-readable storage medium, on which a path segmentation and processing program for a single-layer SVG image is stored. When the path segmentation and processing program for a single-layer SVG image is executed by a processor, the steps of the path segmentation and processing method for a single-layer SVG image as described above are implemented.
[0020] Beneficial effects: The present invention relates to the technical field of computer graphics processing, and discloses a path segmentation and processing method for a single-layer SVG image. By loading an SVG file and displaying the image content in a graphic operation interface, the grouping level information of the SVG file is parsed to determine whether it is a single layer or multiple layers; when a single layer is detected, the sub-element type within the single layer is identified to generate independent sub-path data; based on the sub-path data, a sub-SVG image is generated, displayed and selected, and the selected sub-path data is recombined to generate an updated SVG image, and processing or rendering operations are performed. The present invention achieves efficient distinction between single layers and multiple layers by parsing and judging the grouping level information of the SVG file. Combined with the generation and reorganization of the sub-path data, it can meet the user's needs for displaying, selecting and processing local graphic content, and improves the efficiency and flexibility of SVG image processing. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The present invention will be further described below with reference to the accompanying drawings and embodiments, in which:
[0022] Figure 1 A schematic diagram of an application environment of a path segmentation and processing method for a single-layer SVG image in an embodiment of the present invention;
[0023] Figure 2 It is a flow chart of an embodiment of a method for path segmentation and processing of a single-layer SVG image of the present invention;
[0024] Figure 3 It is a functional module diagram of a preferred embodiment of the path segmentation and processing device for a single-layer SVG image of the present invention;
[0025] Figure 4 A schematic diagram of the structure of a computer device in one embodiment of the present invention;
[0026] Figure 5 FIG. 4 is another schematic diagram of the structure of a computer device in one embodiment of the present invention. DETAILED DESCRIPTION
[0027] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0028] The path segmentation and processing method of a single-layer SVG image provided by the embodiment of the present invention can be applied in the following aspects: Figure 1In an application environment, the user terminal communicates with the server terminal through a network. The server terminal can load the SVG file through the user terminal and display the image content in the graphical operation interface, parse the grouping level information of the SVG file, and judge whether it is a single layer or multiple layers; when it is detected as a single layer, identify the sub-element type in the single layer, and generate independent sub-path data; generate a sub-SVG image based on the sub-path data, display and select, recombining the selected sub-path data to generate an updated SVG image, and perform processing or rendering operations. The present invention realizes efficient distinction between single layers and multiple layers by parsing and judging the grouping level information of the SVG file, and combined with the generation and reorganization of sub-path data, it can meet the user's needs for displaying, selecting and processing local graphic content, and improves the efficiency and flexibility of SVG image processing. Among them, the user terminal can be but not limited to various personal computers, laptops, smart phones, tablet computers and portable wearable devices. The server can be implemented with an independent server or a server cluster composed of multiple servers. The present invention is described in detail below through specific embodiments.
[0029] See also Figure 2 , Figure 2 This is a flow chart of an embodiment of a method for path segmentation and processing of a single-layer SVG image provided by the present invention. It should be noted that although a logical sequence is shown in the flow chart, in some cases, the steps shown or described may be performed in a different order than that shown here.
[0030] like Figure 2 As shown, the path segmentation and processing method of a single-layer SVG image proposed by the present invention includes the following steps:
[0031] S10, loading an SVG file and displaying the image content of the SVG file in a graphical operation interface;
[0032] In this embodiment, the user selects a method for loading an SVG file through a graphical operation interface. This method may include selecting a path from the file system, directly dragging the SVG file to the interface loading area, or loading through a preset data stream. The user clicks the "Load File" button on the interface to trigger the file selection window, selects the target SVG file, and sends a loading instruction to the system; or drags the file in the loading area, the system listens for the drag event and extracts the file path or data stream; the data stream loading method receives the SVG file stream transmitted by the external data source through a specified API interface.
[0033] According to the user's loading instructions, the path or data stream of the target SVG file is parsed to read the content of the SVG file. The read content includes vector data, grouping structure, and attribute configuration of the SVG file. The system calls a file reading module (such as a standard I / O interface) to read the SVG file content corresponding to the file path; or receives the SVG content in the form of a data stream through a network interface and parses it into a standard SVG file data format.
[0034] After the file is read, verify the integrity of the file and the legitimacy of the SVG format. For example, check whether it contains basic SVG tags (such as <svg>tag) and valid file content.
[0035] File integrity verification: calculate file hash values or perform byte-level checks on file contents;
[0036] Format verification: Use a standard SVG parsing library (such as libxml2 or built-in parsing tools) to parse the SVG document structure to ensure that it complies with the SVG specification. If the file is illegal, the user will be prompted with an error message and the loading will be interrupted.
[0037] Extract graphic information from a valid SVG file, including grouping hierarchy, path data, and geometric description. The extracted data is used for subsequent graphic display and interactive operations. Use an SVG parser to read key elements in the file (such as <g> 、 <path>The extracted graph data is stored as an internal data structure, such as JSON format, for subsequent operations.
[0038] Based on the extracted SVG graphic information, the image content is rendered to the drawing area of the graphical operation interface for users to observe and operate. Use a vector graphics rendering engine (such as Canvas or WebGL) to convert path and geometry data into a visual image; set the drawing area in the interface to dynamically render the SVG content; ensure the display ratio and zoom operation so that users can fully view the SVG file content.
[0039] By combining user loading instructions with the reading, verification and parsing of SVG file content, efficient loading and visual display of SVG files are achieved, allowing users to quickly view and operate SVG images, providing a basic guarantee for subsequent path segmentation and graphics processing.
[0040] S20, parsing the grouping level information of the SVG file, and determining whether the SVG file is a single layer or multiple layers;
[0041] In this embodiment, the grouping level information is extracted from the SVG file, that is, parsed <g>Tags (group tags) and their nested structure. Group level information is used to represent the different levels of content organization in the SVG file, including top-level groups and nested groups. Use the SVG parser to read the file <g>Tags, extract the hierarchical structure of grouping tags; build a hierarchical tree structure, store the parent-child relationship of grouping tags as a parseable data structure (such as JSON or tree data structure); for each <g>The tag records its attributes (such as ID, style, and transformation information) for subsequent operations.
[0042] Count the number of group levels and nesting depth in the SVG file, obtain the number of top-level groups and the depth of nested groups under each top-level group. Traverse the extracted group hierarchy tree and count the number of root nodes (top-level groups); for each root node, recursively traverse the child nodes and calculate the nesting depth; store the statistical results, including the number of top-level groups and the maximum nesting depth.
[0043] Based on the statistical grouping level information, determine whether the SVG file is a single layer or multiple layers. The condition for a single layer is that it contains only one top-level group, and the group does not contain nested groups; the condition for multiple layers is that it contains multiple top-level groups or there are nested groups.
[0044] If the number of top-level groups is 1 and the nesting depth is 0, it is determined to be a single layer; if the number of top-level groups is greater than 1, or the nesting depth is greater than 0, it is determined to be multiple layers; the judgment result is returned for subsequent path parsing or layer processing.
[0045] By extracting, counting and judging the grouping level information of SVG files, single-layer and multi-layer files can be quickly distinguished, avoiding manual judgment of layer organization, improving the efficiency and accuracy of SVG file parsing, and providing accurate basic data for subsequent graphics operations.
[0046] S30, when the SVG file is a single layer, performing type identification and processing on sub-elements in the single layer to generate independent sub-path data;
[0047] In this embodiment, all sub-elements in a single layer are parsed to extract basic information of each sub-element, including its type (such as path object, geometric figure, etc.) and attributes (such as color, line width, transformation matrix, etc.). <path> 、 <rect> 、 <circle>Basic graphics or path objects in SVG files.
[0048] Use the SVG parser to traverse the sub-element tags contained in a single layer one by one; extract the type identifier of each sub-element (such as <path>or <rect>), and store related attribute data (such as starting point coordinates, radius, width and height, etc.); store the extracted sub-element information in a structured data form (such as an array or a tree structure).
[0049] Based on the extracted sub-element type information, distinguish whether the sub-element is a path object (Path) or a geometric object (such as a rectangle, circle, etc.). Path objects directly participate in path parsing, and geometric objects need to be further converted into path objects. If the sub-element is <path>, directly marked as a path object, and enter the next step of path parsing; if the child element is <rect> 、 <circle>The geometric figures are marked as geometric objects, their geometric parameters are recorded, and they enter the geometric transformation process.
[0050] Convert the geometry object to a path object (Path) in accordance with the SVG specification. This process ensures that all sub-elements are uniformly stored and processed in the form of paths. Call the corresponding conversion rule according to the geometry type, for example:
[0051] rectangle <rect>Convert to a closed path with four edges;
[0052] Round <circle>Convert to ellipse path;
[0053] Polyline <polyline>Convert to open path;
[0054] Use SVG path commands (such as M, L, C, etc.) to regenerate path data;
[0055] Store the converted path data for subsequent operations.
[0056] Parse the path data of the path object, extract key data such as the control point, starting point, and end point of the path, and divide the path into multiple independent sub-path data according to the path command (such as the M starting point command). Use the path parsing algorithm to parse the path commands (M, L, C, etc.) one by one; each time a new starting point command (M) is encountered, the path data is divided into an independent sub-path; the parsed sub-path data is stored in an array or list form to support subsequent processing.
[0057] According to the parsed path data, all paths in a single layer are divided into multiple independent sub-path data, and each sub-path data corresponds to an independent drawing area. All parsed path objects are traversed and the divided sub-path data are stored separately; a unique identifier is assigned to each sub-path to ensure that it can be directly referenced in subsequent display or selection; atomic properties (such as line width and color) are attached to the sub-path data as needed for display.
[0058] By performing type identification and path parsing on sub-elements within a single layer, sub-elements of different types are uniformly converted into path data, generating independent sub-paths, and achieving standardized management of paths. This processing method improves the flexibility of path data operations and provides support for subsequent sub-path display, selection, and reorganization.
[0059] S40, generating a sub-SVG image based on the sub-path data, and displaying and selecting the sub-SVG image in a graphical operation interface, and recombining the sub-path data corresponding to the selected sub-SVG image to generate an updated SVG image;
[0060] In this embodiment, an independent SVG image is generated for each sub-path according to the parsed and segmented sub-path data. Each sub-SVG image is encapsulated as an independent <svg>element, ensuring that subpaths can be rendered and manipulated individually.
[0061] Traverse the subpath data and create a new one for each subpath <svg>Elements; use path commands (such as M, L, etc.) to embed subpath data <path>In the label; for each <svg>Add a unique identifier (such as the id attribute) and other attributes (such as the view box viewBox) to the element to ensure that the child SVG image can be displayed independently; store the generated child SVG image data as an array or list structure for subsequent display.
[0062] The generated sub-SVG images are displayed in a graphical operation interface for users to view intuitively. When displayed, thumbnails or area displays are used to ensure that users can clearly distinguish the image content corresponding to each sub-path.
[0063] Use the rendering area in the graphical operation interface (such as HTML5 Canvas or SVG visualization container) to load and display each child SVG image; provide an appropriate layout, such as displaying all child SVG images in list or grid form; support interactive operations such as zooming, dragging, and hovering highlighting to enhance the user experience.
[0064] Through the interactive function of the graphical operation interface, users are allowed to select the sub-SVG images that need to be displayed or hidden. The selection results are used to determine which sub-path data will participate in the subsequent update and reorganization. Add selection controls (such as check boxes or buttons) in the display area of each sub-SVG image; record the status of the sub-SVG image selected by the user (such as display or hide), and update the status mark of the corresponding sub-path data; provide select all, reverse selection and cancel operations to improve selection efficiency.
[0065] According to the sub-SVG images selected by the user, the corresponding sub-path data is extracted and reassembled into a complete path set. The reassembled path data is used to generate the updated SVG image. The list of sub-SVG images selected by the user is traversed to extract the sub-path data corresponding to each sub-SVG image; the extracted sub-path data is merged and integrated into a single path set; the original attributes of each sub-path (such as line width, color, etc.) are retained in the new path set to ensure the visual consistency of the image.
[0066] Generate an updated complete SVG image based on the reassembled path data. The updated SVG image is encapsulated as a new <svg>Elements and replace the original image or save it as a new output file. Create a new <svg>element, embed the reassembled path data into it; set the basic properties of the new SVG image (such as view box and size); save the updated SVG image as a file or render it in real time in the graphical operation interface.
[0067] By generating independent sub-SVG images based on sub-path data and supporting user interactive selection, the display and reorganization of local paths in SVG files can be flexibly controlled. Recombining sub-path data to generate updated SVG images not only improves the accuracy and efficiency of image processing, but also provides users with personalized operation methods to meet diverse graphic editing needs.
[0068] S50: Perform processing or rendering operations on the updated SVG image.
[0069] In this embodiment, the updated SVG image is loaded in the graphics operation module to ensure that the generated image data can be correctly read and used for subsequent processing or rendering operations. The updated SVG image data is passed to the graphics processing module; the SVG parser is used to verify the integrity of the updated SVG structure and ensure that the path data is correctly encapsulated in <path>In the tag; initialize the graphics processing parameters (such as color, line width, etc.) to adapt to subsequent processing or rendering.
[0070] Optimize the path data in the updated SVG image to improve the accuracy and efficiency of processing or rendering. This includes smoothing and simplifying the path and processing redundant data. Use path optimization algorithms (such as Bezier curve fitting) to smooth the path data; simplify redundant path points to reduce the amount of calculation during processing or rendering; remove redundant paths or invisible objects to ensure that the output results are accurate and efficient.
[0071] Based on the updated SVG image content, generate operation instructions that are compatible with the processing equipment or rendering engine, such as the G code of the cutting equipment or the drawing instructions of the rendering engine. If the goal is CNC cutting: parse the SVG path data and convert it into G code, including the path movement commands (such as G1, G2) and start and stop point marks; if the goal is graphic drawing: generate drawing instructions based on the path data (such as HTML5 Canvas or WebGL drawing methods); dynamically adjust the instruction content according to the device parameters (such as resolution, speed, etc.) to ensure that the output results meet actual needs.
[0072] According to the generated processing or rendering instructions, operations are performed in the target device or system to achieve physical processing or digital rendering of the updated SVG image.
[0073] If it is physical processing (such as cutting or printing): send instructions to the processing equipment (such as laser cutting machine or printer) and monitor the processing process in real time;
[0074] If it is digital rendering: input the rendering instructions to the display device (such as a screen or a virtual machine) to generate image display effects in real time;
[0075] During operation, it supports pause, adjustment and restart functions to ensure processing or rendering quality.
[0076] The processed physical product or rendered image file is saved as the final result for users to view, use or share. After processing, a processing record is generated, including path execution information and processing time; after rendering, the image file is saved in SVG, PNG, PDF and other formats to meet different usage scenarios; a backtracking function is provided so that users can view the comparison between the original SVG file and the updated image.
[0077] By processing or rendering the updated SVG image, it can flexibly adapt to the needs of digital graphics processing and physical processing equipment. The optimized processing of path data improves the processing and rendering efficiency, ensures the output results are accurate and high-quality, and supports multiple output formats to meet the application needs of users in multiple fields such as graphic design, manufacturing and processing, and data display.
[0078] The present invention relates to the technical field of computer graphics processing, and discloses a path segmentation and processing method for a single-layer SVG image. By loading an SVG file and displaying the image content in a graphic operation interface, the grouping level information of the SVG file is parsed to determine whether it is a single layer or multiple layers; when a single layer is detected, the sub-element type in the single layer is identified to generate independent sub-path data; based on the sub-path data, a sub-SVG image is generated, displayed and selected, and the selected sub-path data is recombined to generate an updated SVG image, and a processing or rendering operation is performed. The present invention realizes efficient distinction between a single layer and multiple layers by parsing and judging the grouping level information of the SVG file, and combined with the generation and reorganization of the sub-path data, it can meet the user's needs for displaying, selecting and processing local graphic content, and improves the efficiency and flexibility of SVG image processing.
[0079] In one embodiment, the above S30 includes:
[0080] S301, when it is detected that the SVG file is a single layer, obtaining type information of sub-elements in the single layer;
[0081] S302, judging whether there is a Path object in the single layer according to the type information of the sub-element;
[0082] S303: when there is a Path object, the path data in the Path object is parsed, and the path data is split into a plurality of independent sub-path data according to a starting point command in the path data;
[0083] S304: when there is no Path object, convert the geometric figure into a Path object, parse the path data in the converted Path object, and split the path data into multiple independent sub-path data according to the starting point command in the path data.
[0084] In this embodiment, all sub-elements in a single layer are parsed to identify the type of each sub-element, such as <path> 、 <rect> 、 <circle>Etc. The sub-element type information is used to determine the existence of the path object and provide a basis for the processing of geometric figures.
[0085] Use the SVG parser to read all sub-elements in a single layer one by one. Extract the type identifier of each sub-element and record the relevant attribute data (such as path definition, geometric parameters, etc.). Store the extracted sub-element type information as structured data (such as a list or tree structure).
[0086] According to the parsed sub-element type information, determine whether a single layer contains <path>Element. The path object (Path) is the core element of the SVG file, which is used to describe the path information of the graphic. Traverse the list of sub-element type information to check whether it exists <path>If detected <path>A label marking the layer as containing path objects; otherwise, it is marked as containing only geometry.
[0087] Parse the path data in the path object, extract the path commands (such as M, L, C, etc. In the SVG path data, M, L, C are letters representing the path commands, which define how the path is drawn.), and split the path data into multiple independent sub-path data according to the starting point command (M).
[0088] Use the path resolution algorithm to parse the path commands one by one. Every time a starting point command (M) is encountered, a new sub-path data structure is created and the subsequent path commands are attributed to this sub-path. The parsed and split sub-path data is stored as an array or list for subsequent use.
[0089] If the sub-elements in a single layer do not contain path objects, the geometric figures (such as rectangles, circles, etc.) need to be converted into path objects according to the SVG specification. The converted path data needs to be further parsed and split into independent sub-path data.
[0090] Depending on the type of geometry, the conversion is done using predefined rules:
[0091] Rectangle: Defines the four sides as four straight line paths.
[0092] Circle or ellipse: Converts to a closed curve path.
[0093] Polyline: Converts to an open path connected by straight paths.
[0094] The converted path data is split into sub-path data according to the starting point command using a path parsing algorithm. All generated sub-path data are stored in a unified data structure to support subsequent processing.
[0095] This embodiment, by identifying and processing the sub-element type, uniformly converts the content in a single layer into path data and splits it into independent sub-paths, which can efficiently support subsequent sub-path display, selection and reorganization operations. It avoids the inconsistency between path and geometric figure processing and improves the processing efficiency and accuracy of path data.
[0096] In one embodiment, the above S40 includes:
[0097] S401, generating an independent sub-SVG image based on the sub-path data, and displaying the sub-SVG image in the graphic operation interface;
[0098] S402, selecting a sub-SVG image to be displayed or hidden, and updating the display content of the graphical operation interface;
[0099] S403, recombining the sub-path data corresponding to the sub-SVG image selected for display to generate an updated SVG image.
[0100] In this embodiment, an independent sub-SVG image is generated for each sub-path according to the parsed sub-path data, and is displayed as a separate SVG element in the graphical operation interface for easy viewing and operation by the user. <svg>Element; embeds subpath data into <path>In the tag, ensure that the path command is complete; set a unique identifier (such as an id attribute) for each child SVG image to facilitate subsequent operations.
[0101] The generated sub-SVG image is loaded in a rendering area (such as HTML5 Canvas or SVG container) of a graphical operation interface; the sub-SVG image can be displayed in a sidebar as a thumbnail, or tiled in a sub-area form.
[0102] Through the user interaction function, the user is allowed to select which sub-SVG images need to be displayed or hidden, and the display content of the graphical operation interface is dynamically updated.
[0103] Provide interactive controls (such as check boxes, switch buttons, etc.) next to each child SVG image for users to choose to display or hide; each time the user makes a selection, record the operation and update the status mark of the child SVG image (such as setting visibility or display attributes).
[0104] Traverse all child SVG images and read their display status; for hidden child SVG images, set their visibility="hidden" or display="none"; for displayed child SVG images, retain their current rendering status.
[0105] Extract the path data of the sub-SVG image that the user chooses to display and reassemble the path data into a new complete SVG image.
[0106] Traverse all sub-SVG images selected by the user for display; extract corresponding sub-path data from each sub-SVG image; store the extracted path data as a new path collection.
[0107] Create a new <svg>Element; embed each path data in the path collection into a new <path>In the tag; set the basic properties of the new SVG image (such as viewBox and size).
[0108] Combine reassembled path data into a complete SVG file; output new SVG image file or render in real time in the interface.
[0109] This embodiment generates independent sub-SVG images based on sub-path data, so that users can flexibly control the display and hiding of graphic content. Through the dynamic extraction and reorganization of path data, the generated updated SVG image can accurately reflect the needs of user selection, while supporting real-time rendering and file output, improving the efficiency of SVG image processing and interactive experience.
[0110] In one embodiment, after the above S20, the method further includes:
[0111] S201, when the SVG file has multiple layers, parsing the layer information in the SVG file layer by layer, and extracting the sub-element type information in each layer;
[0112] S202, judging whether the current layer contains a Path object or a geometric figure according to the sub-element type information in each layer;
[0113] S203, displaying a preview image of each layer through a graphical operation interface, and receiving a target layer selected by a user;
[0114] S204, merging one or more target layers selected by the user into a single-layer SVG file to generate a merged single layer;
[0115] S205, performing sub-element type identification and path data parsing operations on the merged single layer to generate an updated SVG image;
[0116] S206, performing processing or rendering operations on the updated SVG image to generate cutting instructions or output an image file.
[0117] In this embodiment, for a multi-layer SVG file, the layer structure is parsed layer by layer, and sub-element type information (such as <path> 、 <rect> 、 <circle>The sub-element type information is the basis for subsequent judgment of layer content and execution of operations.
[0118] Use the SVG parser to iterate over each layer ( <g>Tag), extract the sub-elements one by one; record the type identifier of each sub-element (such as <path>or <rect>) and attributes (such as path commands, geometric parameters, etc.); store the parsing results as hierarchical structure data (such as tree structure or JSON format) for subsequent processing.
[0119] Based on the sub-element type information of each layer, determine whether the layer contains a path object (Path) or a geometric figure. Path objects are directly used for path parsing, while geometric figures need to be further converted into path objects.
[0120] Traverse the list of sub-element types of each layer: if it is detected <path>Tag, marking the layer as containing path objects; if detected <rect> 、 <circle>Geometric graphics tags such as the one used for layer identification are used to mark the layer as containing geometric graphics; the judgment result of the layer content is associated with the sub-element type information and stored.
[0121] The preview image of each layer is displayed through the graphical operation interface for users to intuitively view and select. The target layer selected by the user will participate in the subsequent layer merging operation.
[0122] Preview image generation: Use the SVG rendering engine to render the data of each layer into an independent preview image; ensure that the layer content is visible and support zooming and dragging operations.
[0123] User selection function: In the graphical operation interface, a check box or interactive button is provided for each layer; the target layer list selected by the user is recorded, and the interface display is updated in real time.
[0124] Merge the layer contents selected by the user into a single-layer structured SVG file for unified processing and operation.
[0125] Extracts user-selected layer data; creates new <g>Tags to embed the sub-elements of the selected layer into them; remove duplicate or redundant layer properties (such as style and transformation information) to ensure that the merged layer structure is simple and complete.
[0126] The sub-element type of the merged single layer content is identified and the path data is parsed. The result of the path data parsing is used to generate the updated SVG image.
[0127] All sub-elements in the merged layer are classified by type (such as path objects and geometric figures); path commands are extracted from path objects; geometric figures are converted into path objects and parsed into path data; independent sub-path data are generated and stored in a structured data format.
[0128] According to the updated SVG image content, processing or rendering operations are performed. Processing operations are usually used to generate cutting instructions, and rendering operations are used to generate visual output files.
[0129] Processing operation: parse the path data and generate the instructions (such as G code) required by the processing equipment; send the instructions to the processing equipment to execute the operation.
[0130] Rendering operation: Use the rendering engine to generate high-resolution visual images; output to file formats such as SVG, PDF, PNG, etc.
[0131] It may also include or be understood as:
[0132] Physical cutting: Physically separate, carve or shape materials by generating operating instructions for processing equipment (such as laser cutting machines, CNC machine tools). Example: Laser cutting: Convert SVG path data into G code to control the cutting machine to move along the specified path. Engraving: Generate engraving instructions based on the outline of the SVG path to control the machine tool.
[0133] Digital cutting: Segment, extract or reorganize image content in digital space to meet the needs of subsequent design, simulation or manufacturing. Example: Image segmentation: Segment the path or geometric data in SVG into multiple independent parts according to user needs. Module extraction: Generate separate sub-SVG files or formatted data for insertion into other design tools or embedded systems.
[0134] Digital processing: Digitally process SVG data to adapt it to specific equipment, tools or application scenarios. Example: Grid processing: Convert vector graphics into raster data for 3D printing or simulation. Path optimization: Smooth SVG path data to reduce redundant points and improve equipment processing efficiency. Data export: Convert processed SVG data into other standard formats (such as DXF, G-code, JSON).
[0135] This embodiment achieves accurate parsing of complex layer structures and user interaction by parsing multi-layer SVG files layer by layer and extracting sub-element type information. It merges the layers selected by the user into a single layer structure, unifies the path parsing and processing flow, and improves the efficiency and flexibility of image processing and rendering. The updated SVG image finally generated supports a variety of application requirements.
[0136] In one embodiment, the above S10 includes:
[0137] S101, receiving a user's instruction to load an SVG file through a graphical operation interface;
[0138] S102, obtaining a path or data stream of the SVG file according to the instruction;
[0139] S103, reading the SVG file content according to the acquired path or data stream;
[0140] S104, verifying the read SVG file content;
[0141] S105, parsing the verified SVG file, extracting graphic information from the SVG file and generating drawing data;
[0142] S106: Load the drawing data into a drawing area of a graphic operation interface for display.
[0143] In this embodiment, in the graphical operation interface, the user triggers the operation of loading the SVG file through an interactive method. The user's loading method can be to select a file path, drag the file to the interface, or load it through a predefined data stream.
[0144] Provide interface controls (such as a "load file" button) for users to click to trigger a file selection window; or set a drag event listener in the loading area to capture the SVG file dragged by the user; receive the externally transmitted SVG file data stream in the specified interface; record the user's operation as a loading instruction and pass it to the subsequent processing module.
[0145] According to the source of the user's loading instruction (path selection, dragging, data stream transmission), the specific path or data stream content of the SVG file is obtained for further processing.
[0146] File path method: Use the standard I / O interface to read the local path selected by the user;
[0147] Drag mode: listen to drag events and extract the absolute path of the dragged file;
[0148] Data stream mode: Receive the externally transmitted SVG file stream through the API interface, cache it as a local temporary file or parse it directly.
[0149] Load and read the contents of an SVG file through the specified path or data stream, ensuring that the file format and data can be obtained correctly. Open the file path or data stream and read the file content as text format; use standard file reading interfaces (such as FileReader or fs module) to extract the SVG content; store the file content as a string for subsequent parsing and verification.
[0150] Check the integrity and legality of the SVG file to ensure that the file format complies with the SVG specification and eliminate errors or incomplete file content. Check the start and end tags of the file to ensure that they contain valid <svg>Tags; verify the structure in the file (such as <g> 、 <path>tags are closed correctly); use the SVG parser to detect syntax errors or unsupported features and prompt the user to correct them.
[0151] Parse the contents of SVG files, extract graphic element information (such as paths, groups, and geometric figures), and generate structured data for drawing (such as path commands, coordinates, and style information). Use the SVG parsing library to read the file content, extract key elements (such as <path> 、 <rect> 、 <circle>etc.); parse the attributes of each element (such as path data, coordinates, color, etc.) and store them as drawing data in JSON or similar format; process layer grouping information to ensure that the hierarchical structure is preserved intact in the drawing data.
[0152] Render the parsed drawing data into the drawing area of the graphical operation interface and display it to the user in a visual form. Use HTML5 Canvas, WebGL or SVG native rendering tools to load the drawing data into the interface; set the initial view box (viewBox) and scale of the drawing area to fully display the SVG content; support interactive functions such as zooming and panning, and users can freely view image details.
[0153] This embodiment can efficiently complete the overall process of file loading, format verification, graphic parsing and content visualization by loading SVG files from a graphical operation interface and displaying the image content. It provides users with convenient file operations and real-time feedback capabilities, laying the foundation for subsequent SVG graphics processing and path segmentation operations.
[0154] In one embodiment, the above S20 includes:
[0155] S207, extracting grouping level information from the SVG file;
[0156] S208, parsing the group level information to obtain a hierarchical structure of each group, wherein the hierarchical structure includes specific levels of top-level groups and nested groups;
[0157] S209, based on the hierarchical structure obtained from the grouping level information, counting the number of top-level groups and the hierarchical depth of the nested groups, and generating a statistical result including the number of top-level groups and the hierarchical depth of the nested groups;
[0158] S210: Determine whether the SVG file is a single layer or multiple layers according to the statistical result.
[0159] In this embodiment, the group-related information is extracted from the structure of the SVG file to identify all <g>Tags and their nesting relationships. Grouping level information is used to represent the organizational structure of SVG content.
[0160] Use the SVG parser to read the file one by one <g>Tags; extract basic attributes of each group (such as id, class, transform, etc.); build a parent-child relationship tree of the group, and store the group hierarchy information as structured data (such as a tree structure or JSON format).
[0161] Parse the extracted group level information and build the hierarchical structure of each group, including the nesting level and specific relationship of the group. Traverse the group level data and record the parent node and child node of each group; calculate the nesting level of each group and mark the top group (group without parent node) and nested group (group with parent node); store the group hierarchy as a tree model including group relationship and level depth.
[0162] Count the number of top-level groups (root nodes) in the group hierarchy, and the maximum depth of nested groups. These statistical results are the basis for judging the layer structure. Traverse the group hierarchy and count the number of all top-level groups (root nodes); recursively traverse the child nodes of each top-level group and calculate the depth of nested levels; generate statistical results, including the number of top-level groups and the maximum depth of nested groups.
[0163] According to the group statistics, determine whether the SVG file is a single layer or multiple layers. The single layer condition is that there is only one top-level group and no nested groups; the multi-layer condition is that there are multiple top-level groups or nested groups. If the statistical results show that the number of top-level groups is 1 and the nested group depth is 0, it is determined to be a single layer; if the statistical results show that the number of top-level groups is greater than 1, or the nested group depth is greater than 0, it is determined to be multiple layers; the judgment result is output to the subsequent processing module.
[0164] This embodiment can quickly distinguish single-layer and multi-layer structures by extracting and parsing the grouping level information of SVG files, providing accurate data support for subsequent path parsing and layer operations, simplifying the layer judgment process, and being suitable for efficient parsing and processing of complex SVG files.
[0165] In one embodiment, the above S210 includes:
[0166] S2101: When the statistical result includes only one top-level group and no nested group exists, it is determined that the SVG file is a single layer.
[0167] S2102: If the statistical result includes multiple top-level groups, or there are nested groups, it is determined that the SVG file has multiple layers.
[0168] In this embodiment, whether the SVG file is a single layer is determined based on the number of top-level groups and the depth of nested groups in the statistical results. The condition for a single layer is that there is only one top-level group and no other groups are nested in the group.
[0169] Check the number of top-level groups in the statistics: If the number is 1, continue to check the depth of nested groups;
[0170] Check the nested grouping depth in the statistical results: if the nested grouping depth is 0, it is judged as a single layer;
[0171] Returns the single layer judgment result.
[0172] Example: The statistical results are:
[0173] {
[0174] "Number of top-level groups": 1,
[0175] "Maximum nesting depth": 0
[0176] }
[0177] According to the rules, the SVG file is determined to be a single layer.
[0178] If the statistical result shows that there are multiple top-level groups, or even if there is only one top-level group but there are nested groups inside it, the SVG file is determined to be multi-layered.
[0179] Check the number of top-level groups in the statistical results: if the number is greater than 1, it is directly determined to be multiple layers;
[0180] Check the depth of nested groups: if the nesting depth is greater than 0, it is considered to be multiple layers even if the number of top-level groups is 1;
[0181] Returns the multi-layer determination result.
[0182] Example: The statistical results are:
[0183] {
[0184] "Number of top-level groups":2,
[0185] "Maximum nesting depth": 0
[0186] }
[0187] According to the rules, the SVG file is determined to be multi-layered.
[0188] For complex SVG files, the statistical results are processed in layers: first, the number of top-level groups is checked separately; then, the nesting depth is checked to see if it is 0; finally, the results of the two conditions are combined and the judgment is returned.
[0189] In the dynamic analysis scene, the group information is analyzed step by step and the statistical results are updated in real time. Whenever the statistical results change, it is dynamically determined whether it is a single layer or multiple layers.
[0190] This embodiment can quickly distinguish single-layer and multi-layer files by determining the layer structure of the SVG file based on the statistical results, simplifying the logic of layer processing. It is applicable to SVG files of different complexities, ensuring accurate determination results, and providing clear guidance for subsequent path parsing and graphic operations.
[0191] In one embodiment, a path segmentation and processing device for a single-layer SVG image is provided, and the path segmentation and processing device for a single-layer SVG image corresponds one-to-one to the path segmentation and processing method for a single-layer SVG image in the above embodiment. Figure 3 , Figure 3 This is a functional module diagram of a preferred embodiment of a path segmentation and processing device for a single-layer SVG image of the present invention. File loading and visualization module 10, layer parsing module 20, path parsing and data generation module 30, sub-image generation module 40 and graphics processing and rendering module 50. The functional modules are described in detail as follows:
[0192] A file loading and visualization module 10, used to load an SVG file and display the image content of the SVG file in a graphical operation interface;
[0193] A layer parsing module 20, used to parse the grouping level information of the SVG file and determine whether the SVG file is a single layer or multiple layers;
[0194] The path parsing and data generating module 30 is used to identify and process the sub-elements in the single layer when the SVG file is a single layer, and generate independent sub-path data;
[0195] A sub-image generation module 40 is used to generate a sub-SVG image based on the sub-path data, and display and select it in a graphical operation interface, and reassemble the sub-path data corresponding to the selected sub-SVG image to generate an updated SVG image;
[0196] The graphics processing and rendering module 50 is used to perform processing or rendering operations on the updated SVG image.
[0197] In one embodiment, the path parsing and data generating module 30 is specifically used to:
[0198] When it is detected that the SVG file is a single layer, obtaining type information of sub-elements in the single layer;
[0199] According to the type information of the sub-element, determining whether there is a Path object in the single layer;
[0200] When there is a Path object, the path data in the Path object is parsed, and the path data is split into multiple independent sub-path data according to the starting point command in the path data;
[0201] When there is no Path object, the geometric figure is converted into a Path object, the path data in the converted Path object is parsed, and the path data is split into multiple independent sub-path data according to the starting point command in the path data.
[0202] In one embodiment, the subgraph generation module 40 is specifically configured to:
[0203] Generate an independent sub-SVG image based on the sub-path data, and display the sub-SVG image in the graphical operation interface;
[0204] Select the sub-SVG image to be displayed or hidden, and update the display content of the graphical operation interface;
[0205] The sub-path data corresponding to the sub-SVG image selected for display is reassembled to generate an updated SVG image.
[0206] In one embodiment, the layer parsing module 20 is specifically used for:
[0207] When the SVG file has multiple layers, the layer information in the SVG file is parsed layer by layer to extract the sub-element type information in each layer;
[0208] According to the sub-element type information in each layer, determine whether the current layer contains a Path object or a geometric figure;
[0209] Display the preview image of each layer through the graphical operation interface and receive the target layer selected by the user;
[0210] Merge one or more target layers selected by the user into a single-layer SVG file to generate a merged single layer;
[0211] Perform sub-element type identification and path data parsing operations on the merged single layer to generate an updated SVG image;
[0212] A processing or rendering operation is performed on the updated SVG image to generate cutting instructions or output an image file.
[0213] In one embodiment, the file loading and visualization module 10 is specifically used for:
[0214] Receiving a user's instruction to load an SVG file through a graphical operation interface;
[0215] Obtain the path or data stream of the SVG file according to the instruction;
[0216] Read the SVG file content according to the obtained path or data stream;
[0217] Verify the content of the read SVG file;
[0218] Parsing the verified SVG file, extracting graphic information from the SVG file and generating drawing data;
[0219] The drawing data is loaded into a drawing area of a graphic operation interface for display.
[0220] In one embodiment, the layer parsing module 20 is specifically used for:
[0221] Extracting grouping level information from the SVG file;
[0222] Parsing the grouping level information to obtain a hierarchical structure of each group, wherein the hierarchical structure includes specific levels of top-level groups and nested groups;
[0223] Based on the hierarchical structure obtained from the grouping level information, counting the number of top-level groups and the hierarchical depth of nested groups, and generating a statistical result including the number of top-level groups and the hierarchical depth of nested groups;
[0224] According to the statistical result, it is determined whether the SVG file is a single layer or multiple layers.
[0225] In one embodiment, the layer parsing module 20 is specifically used for:
[0226] When the statistical result includes only one top-level group and no nested group exists, it is determined that the SVG file is a single layer;
[0227] If the statistical result includes multiple top-level groups, or there are nested groups, it is determined that the SVG file has multiple layers.
[0228] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 4 As shown. The computer device includes a processor, a memory, a network interface and a database connected via a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile and / or volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external user terminal through a network connection. When the computer program is executed by the processor, it implements the functions or steps of a server-side method for path segmentation and processing of a single-layer SVG image.
[0229] In one embodiment, a computer device is provided. The computer device may be a user terminal, and its internal structure diagram may be as follows: Figure 5 As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected via a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external server via a network connection. When the computer program is executed by the processor, it implements the functions or steps on the user side of a method for path segmentation and processing of a single-layer SVG image
[0230] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the following steps are implemented:
[0231] Loading an SVG file and displaying the image content of the SVG file in a graphical operation interface;
[0232] Parsing the grouping level information of the SVG file to determine whether the SVG file is a single layer or multiple layers;
[0233] When the SVG file is a single layer, the sub-elements in the single layer are identified and processed, and independent sub-path data is generated;
[0234] Generate a sub-SVG image based on the sub-path data, display and select it in a graphical operation interface, and reassemble the sub-path data corresponding to the selected sub-SVG image to generate an updated SVG image;
[0235] A processing or rendering operation is performed on the updated SVG image.
[0236] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0237] Loading an SVG file and displaying the image content of the SVG file in a graphical operation interface;
[0238] Parsing the grouping level information of the SVG file to determine whether the SVG file is a single layer or multiple layers;
[0239] When the SVG file is a single layer, the sub-elements in the single layer are identified and processed, and independent sub-path data is generated;
[0240] Generate a sub-SVG image based on the sub-path data, display and select it in a graphical operation interface, and reassemble the sub-path data corresponding to the selected sub-SVG image to generate an updated SVG image;
[0241] A processing or rendering operation is performed on the updated SVG image.
[0242] It should be noted that the above functions or steps that can be implemented by the computer-readable storage medium or computer device can refer to the relevant descriptions on the server side and the user side in the aforementioned method embodiment. To avoid repetition, they will not be described one by one here.
[0243] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0244] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0245] It should be noted that if software tools or components other than those of the Company appear in the embodiments of the present application, they are only used for illustration and do not represent actual use. The above-described embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the above-mentioned embodiments, a person of ordinary skill in the art should understand that the technical solutions described in the above-mentioned embodiments can still be modified, or some of the technical features thereof can be replaced by equivalents; and these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.< / g> < / g> < / circle> < / rect> < / path> < / path> < / g> < / svg> < / g> < / circle> < / rect> < / path> < / rect> < / path> < / g> < / circle> < / rect> < / path> < / path> < / svg> < / path> < / svg> < / path> < / path> < / path> < / circle> < / rect> < / path> < / path> < / svg> < / svg> < / svg> < / path> < / svg> < / svg> < / polyline> < / circle> < / rect> < / circle> < / rect> < / path> < / rect> < / path> < / circle> < / rect> < / path> < / g> < / g> < / g> < / path> < / g> < / svg>
Claims
1. A path segmentation and processing method for a single-layer SVG image, characterized in that: The following steps are involved: Loading an SVG file and displaying the image content of the SVG file in a graphical operation interface; Parsing the grouping level information of the SVG file to determine whether the SVG file is a single layer or multiple layers; When the SVG file is a single layer, the sub-elements in the single layer are identified and processed to generate independent sub-path data; Generate a sub-SVG image based on the sub-path data, display and select it in a graphical operation interface, and reassemble the sub-path data corresponding to the selected sub-SVG image to generate an updated SVG image; A processing or rendering operation is performed on the updated SVG image.
2. The path segmentation and processing method of a single-layer SVG image according to claim 1, characterized in that: When the SVG file is a single layer, the sub-elements in the single layer are identified and processed, and independent sub-path data is generated, including: When it is detected that the SVG file is a single layer, obtaining type information of sub-elements in the single layer; According to the type information of the sub-element, determining whether there is a Path object in the single layer; When there is a Path object, the path data in the Path object is parsed, and the path data is split into multiple independent sub-path data according to the starting point command in the path data; When there is no Path object, the geometric figure is converted into a Path object, the path data in the converted Path object is parsed, and the path data is split into multiple independent sub-path data according to the starting point command in the path data.
3. The path segmentation and processing method of a single-layer SVG image according to claim 1, characterized in that: Generating a sub-SVG image based on the sub-path data, displaying and selecting the sub-SVG image in a graphical operation interface, and recombining the sub-path data corresponding to the selected sub-SVG image to generate an updated SVG image, including: Generate an independent sub-SVG image based on the sub-path data, and display the sub-SVG image in the graphical operation interface; Select the sub-SVG image to be displayed or hidden, and update the display content of the graphical operation interface; The sub-path data corresponding to the sub-SVG image selected for display is reassembled to generate an updated SVG image.
4. The path segmentation and processing method of a single-layer SVG image according to claim 1, characterized in that: After parsing the grouping level information of the SVG file and determining whether the SVG file is a single layer or multiple layers, the method further includes: When the SVG file has multiple layers, the layer information in the SVG file is parsed layer by layer to extract the sub-element type information in each layer; According to the sub-element type information in each layer, determine whether the current layer contains a Path object or a geometric figure; Display the preview image of each layer through the graphical operation interface and receive the target layer selected by the user; Merge one or more target layers selected by the user into a single-layer SVG file to generate a merged single layer; Perform sub-element type identification and path data parsing operations on the merged single layer to generate an updated SVG image; A processing or rendering operation is performed on the updated SVG image to generate cutting instructions or output an image file.
5. The path segmentation and processing method of a single-layer SVG image as claimed in claim 1, characterized in that: Loading an SVG file and displaying the image content of the SVG file in a graphical operation interface includes: Receiving a user's instruction to load an SVG file through a graphical operation interface; Obtain the path or data stream of the SVG file according to the instruction; Read the SVG file content according to the obtained path or data stream; Verify the content of the read SVG file; Parsing the verified SVG file, extracting graphic information from the SVG file and generating drawing data; The drawing data is loaded into a drawing area of a graphic operation interface for display.
6. The path segmentation and processing method of a single-layer SVG image according to claim 1, characterized in that: Parsing the grouping level information of the SVG file to determine whether the SVG file is a single layer or multiple layers includes: Extracting grouping level information from the SVG file; Parsing the grouping level information to obtain a hierarchical structure of each group, wherein the hierarchical structure includes specific levels of top-level groups and nested groups; Based on the hierarchical structure obtained from the grouping level information, counting the number of top-level groups and the hierarchical depth of nested groups, and generating a statistical result including the number of top-level groups and the hierarchical depth of nested groups; According to the statistical result, it is determined whether the SVG file is a single layer or multiple layers.
7. The path segmentation and processing method of a single-layer SVG image according to claim 6, characterized in that: Judging, according to the statistical result, whether the SVG file is a single layer or multiple layers includes: When the statistical result includes only one top-level group and no nested group exists, it is determined that the SVG file is a single layer; If the statistical result includes multiple top-level groups, or there are nested groups, it is determined that the SVG file has multiple layers.
8. A path segmentation and processing device for a single-layer SVG image, characterized in that: The path segmentation and processing device of the single-layer SVG image comprises: A file loading and visualization module, used to load an SVG file and display the image content of the SVG file in a graphical operation interface; A layer parsing module, used to parse the grouping level information of the SVG file and determine whether the SVG file is a single layer or multiple layers; A path parsing and data generation module, for, when the SVG file is a single layer, performing type identification and processing on sub-elements in the single layer, and generating independent sub-path data; A sub-image generation module, for generating a sub-SVG image based on the sub-path data, and displaying and selecting the sub-SVG image in a graphical operation interface, and recombining the sub-path data corresponding to the selected sub-SVG image to generate an updated SVG image; The graphics processing and rendering module is used to perform processing or rendering operations on the updated SVG image.
9. A computer device, characterized in that: The computer device includes a memory, a processor, and a path segmentation and processing program for a single-layer SVG image stored in the memory and executable on the processor. When the path segmentation and processing program for a single-layer SVG image is executed by the processor, the steps of the path segmentation and processing method for a single-layer SVG image are implemented as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The storage medium stores a path segmentation and processing program for a single-layer SVG image. When the path segmentation and processing program for a single-layer SVG image is executed by a processor, the steps of the path segmentation and processing method for a single-layer SVG image as described in any one of claims 1-7 are implemented.
Citation Information
Cited By
Storage pool creation method and device, equipment, medium and product
CN121387205A