Canvas element copying and pasting method and device, electronic equipment and storage medium
By encoding and type conversion of canvas element data, depositing it into the paste board, and corresponding data analysis and pasting operations are performed according to the support of the target paste position, the problem of large amount of data and long analysis during copying and pasting in the prior art is solved, and the user experience is improved.
Patent Information
- Application Number
- CN202411610255.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-12
- Publication Date
- 2025-03-21
AI Technical Summary
In the prior art, when copying and pasting canvas elements, the amount of data on the paste board is large, and it takes a long time to parse mixed data, which affects the user experience.
By obtaining the data of the canvas element to be copied, encode the data to obtain the custom type data, and store it with the alternative type data into the pasteboard. After receiving the pasting request, determine whether the target pasting location supports custom type data. If it is supported, parse the custom type data for pasting. If it is not supported, parse the alternative type data for pasting.
Effectively reduce the amount of paste board data and the time of parsing data, improving the user experience.
Smart Images

Figure CN119668893A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data copying and pasting, and in particular to a method, device, electronic device and storage medium for copying and pasting canvas elements. Background Art
[0002] In the printing industry, when editing print content, it is often necessary to copy and paste elements in the canvas. The copied elements can be pasted as a new element with the same content in the own software, or they can be pasted as images in other software that supports pasting images.
[0003] However, in the prior art, when copying and pasting elements in the canvas, the element data is usually mixed with the graphic data, and the element data is parsed while parsing the graphic data during pasting. However, this copy-paste method has a large amount of data on the clipboard, and it takes a long time to parse the mixed data, which affects the user experience.
[0004] Therefore, the existing technology has technical problems such as a large amount of data on the clipboard during copying and pasting, and a long time spent parsing mixed data, which affects the user experience and needs to be improved. Summary of the invention
[0005] In view of this, it is necessary to provide a canvas element copy and paste method, device, electronic device and storage medium to solve the technical problems in the prior art that the amount of data on the clipboard is large during the copy and paste process, and that parsing mixed data takes a long time, affecting the user experience.
[0006] In order to solve the above problems, on the one hand, the present invention provides a method for copying and pasting canvas elements, comprising: Acquire the canvas element data to be copied, perform data encoding on the canvas element data to be copied to obtain custom type data, perform data type conversion on the canvas element data to be copied to obtain candidate type data, and store the custom type data and the candidate type data into the clipboard; After receiving the paste request, determine whether the target paste location supports custom type data. If so, parse the custom type data and perform the paste operation. If not, parse the alternative type data and perform the paste operation.
[0007] In a possible implementation, the custom type data includes canvas element encoding data and an encoding type field.
[0008] In a possible implementation, data encoding is performed on the canvas element data to be copied to obtain custom type data, including: Performing data format conversion on the canvas element data to be copied to obtain JSON format data, and performing bytecode encoding on the JSON format data to obtain canvas element encoding data; Encode the data tag encoding type for the canvas element to get the encoding type field.
[0009] In a possible implementation, the candidate type data includes image type data, and the candidate type data is obtained by performing data type conversion on the canvas element data to be copied, including: The canvas element data to be copied is parsed according to the preset image library to generate image type data.
[0010] In a possible implementation, parsing the custom type data and performing the paste operation includes: Determine the corresponding decoding method according to the encoding type field, and decode the canvas element encoding data according to the decoding method to obtain JSON string data; Serialize the JSON string data to get the data object to be pasted; Paste the data object to be pasted to the target paste position.
[0011] In a possible implementation, parsing the candidate type data and performing the paste operation includes: Determine whether the target paste location supports image type data. If so, parse the image type data and perform the paste operation.
[0012] In a possible implementation, the candidate type data further includes text type data, and the method further includes: After receiving the paste request, if the pasteboard does not contain custom type data and image type data, parse the text type data and perform the paste operation.
[0013] On the other hand, the present invention also provides a canvas element copy and paste device, comprising: A canvas element copying unit, used for obtaining the canvas element data to be copied, performing data encoding on the canvas element data to be copied to obtain custom type data, performing data type conversion on the canvas element data to be copied to obtain candidate type data, and storing the custom type data and the candidate type data into a clipboard; The canvas element pasting unit is used to determine whether the target paste position supports custom type data after receiving a paste request. If it supports custom type data, it parses the custom type data and performs a paste operation. If it does not support custom type data, it parses the alternative type data and performs a paste operation.
[0014] On the other hand, the present invention also provides an electronic device, including a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the above-mentioned canvas element copying and pasting method is implemented.
[0015] On the other hand, the present invention further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the above-mentioned canvas element copy and paste method is implemented.
[0016] The beneficial effects of the present invention are as follows: in the canvas element copy and paste method provided by the present invention, firstly, the canvas element data to be copied is obtained, the canvas element data to be copied is data-encoded to obtain custom type data, the data type of the canvas element data to be copied is converted to obtain alternative type data, and the custom type data and the alternative type data are stored in the pasteboard; then after receiving the paste request, it is determined whether the target paste position supports the custom type data, if the custom type data is supported, the custom type data is parsed and the paste operation is performed, if the custom type data is not supported, the alternative type data is parsed and the paste operation is performed. The present invention reduces the amount of data on the pasteboard by encoding the canvas element data to be copied into custom type data, converting the canvas element data to be copied into custom type data and alternative type data respectively, and performing corresponding paste operations according to the data types supported by the target paste position, thereby effectively reducing the time for parsing data and improving user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0018] Figure 1 A schematic diagram of a flow chart of an embodiment of a method for copying and pasting canvas elements provided by the present invention; Figure 2 A schematic diagram of a process of obtaining user-defined type data by encoding data in an embodiment of the present invention; Figure 3 A schematic diagram of a process of custom data parsing and pasting according to an embodiment of the present invention; Figure 4 A schematic diagram of the structure of an embodiment of a canvas element copying and pasting device provided by the present invention; Figure 5 A schematic structural diagram of an embodiment of an electronic device provided by the present invention. DETAILED DESCRIPTION
[0019] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0020] In the description of the embodiments of the present invention, unless otherwise specified, "multiple" means two or more than two. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" may mean: A exists alone, A and B exist at the same time, and B exists alone.
[0021] The descriptions of "first" and "second" in the embodiments of the present invention are only used for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of the indicated technical features. Therefore, the technical features defined as "first" and "second" may explicitly or implicitly include at least one of the features.
[0022] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0023] Before presenting the embodiments, the following terms are explained.
[0024] Custom type data: refers to the type stored in the clipboard in a custom array. Common types include text and bytecode. The text type generally does not require encoding or decoding when used, while the bytecode type requires encoding or decoding during use.
[0025] The present invention provides a method, device, electronic device and storage medium for copying and pasting canvas elements, which are described below respectively.
[0026] Figure 1 A schematic diagram of a flow chart of an embodiment of a method for copying and pasting canvas elements provided by the present invention is shown in FIG. Figure 1 As shown, the canvas element copy and paste method includes: S101, obtaining canvas element data to be copied, performing data encoding on the canvas element data to be copied to obtain custom type data, performing data type conversion on the canvas element data to be copied to obtain candidate type data, and storing the custom type data and the candidate type data into a clipboard; S102: after receiving the paste request, determine whether the target paste position supports the custom type data; if so, parse the custom type data and perform the paste operation; if not, parse the alternative type data and perform the paste operation.
[0027] Compared with the prior art, the canvas element copy and paste method provided by the embodiment of the present invention first obtains the canvas element data to be copied, performs data encoding on the canvas element data to be copied to obtain custom type data, performs data type conversion on the canvas element data to be copied to obtain alternative type data, and stores the custom type data and the alternative type data in the clipboard; then after receiving the paste request, it is determined whether the target paste position supports the custom type data, if it supports the custom type data, the custom type data is parsed and the paste operation is performed, if it does not support the custom type data, the alternative type data is parsed and the paste operation is performed. The present invention reduces the amount of data on the clipboard by encoding the canvas element data to be copied into custom type data, converting the canvas element data to be copied into custom type data and alternative type data respectively, and performing corresponding paste operations according to the data types supported by the target paste position, thereby effectively reducing the time for parsing data and improving user experience.
[0028] In some embodiments of the present invention, the custom type data includes canvas element encoding data and an encoding type field.
[0029] Specifically, in order to reduce the amount of data on the clipboard and facilitate the encoding and decoding of the data, the custom type data in the embodiment includes canvas element encoding data and encoding type field. The canvas element encoding data is data in bytecode format obtained by encoding the canvas element data to be copied, and the encoding type field is used to store the encoding type so that the data can be accurately identified and parsed when decoding the data.
[0030] In some embodiments of the present invention, Figure 2 The following is a flow chart of obtaining custom type data by encoding data in an embodiment of the present invention. Figure 2 As shown, the data of the canvas element to be copied is encoded to obtain the custom type data, including: S201, converting the data format of the canvas element data to be copied to obtain JSON format data, and performing bytecode encoding on the JSON format data to obtain canvas element encoded data; S202. Mark the encoding type of the canvas element encoding data to obtain an encoding type field.
[0031] Specifically, in the data encoding process, in order to effectively reduce the bytecode size, the embodiment first converts the canvas element data to be copied into JSON format data, and the software then performs bytecode encoding on the JSON format data to obtain the canvas element encoding data. At the same time, in order to facilitate subsequent decoding operations, it is also necessary to generate an encoding type field according to the encoding type in the bytecode encoding process.
[0032] In some embodiments of the present invention, the candidate type data includes image type data, and the candidate type data is obtained by performing data type conversion on the canvas element data to be copied, including: The canvas element data to be copied is parsed according to the preset image library to generate image type data.
[0033] Specifically, in addition to encoding the canvas element data to be copied as custom type data, the embodiment also converts the canvas element data to be copied into alternative type data, so as to perform a paste operation using the alternative type data when the target paste position does not support the custom type data.
[0034] Among them, the alternative type data includes image type data. In the process of generating the image type data, the embodiment passes the canvas element data to be copied to the preset image library, and parses the element data through the preset image library to generate the image type data.
[0035] In some embodiments of the present invention, Figure 3 Schematic diagram of the process of custom data parsing and pasting according to an embodiment of the present invention, such as Figure 3 As shown, parse the custom type data and perform the paste operation, including: S301, determining a corresponding decoding method according to the encoding type field, and decoding the canvas element encoding data according to the decoding method to obtain JSON string data; S302, serialize the JSON string data to obtain the data object to be pasted; S303: Paste the data object to be pasted to the target pasting position.
[0036] Specifically, after receiving the paste request, it is necessary to first determine whether the target paste location supports custom type data. In the embodiment, generally speaking, if the target paste location is the software itself, it supports custom type data, and if the target paste location is other software, it usually does not support custom type data. The embodiment parses the corresponding data according to the data format supported by the target paste location and performs the paste operation.
[0037] In the process of parsing and pasting custom type data, the embodiment first determines the decoding method corresponding to the custom type data according to the encoding type field, and decodes the canvas element encoding data into JSON string data according to the determined decoding method, and then serializes the JSON string data to obtain the data object to be pasted, and finally pastes the data object to be pasted to the target paste position.
[0038] In some embodiments of the present invention, parsing the candidate type data and performing the paste operation includes: Determine whether the target paste location supports image type data. If so, parse the image type data and perform the paste operation.
[0039] Specifically, when the target paste position does not support custom type data, the embodiment first determines whether the target paste position supports image type data. If it supports image type data, the embodiment parses the image type data saved in the pasteboard and pastes it to the corresponding position; if it does not support, the paste operation ends.
[0040] In some embodiments of the present invention, the candidate type data further includes text type data, and the method further includes: After receiving the paste request, if the pasteboard does not contain custom type data and image type data, parse the text type data and perform the paste operation.
[0041] Specifically, in order to ensure that the clipboard can quickly copy and paste canvas element data while still retaining the original text copy and paste function, the alternative type data also includes text type data. During the pasting process, if it is determined that neither custom type data nor image type data exists in the clipboard, the text type data is parsed and the paste operation is performed, thereby completing the conventional text copy and paste operation.
[0042] In summary, in order to reduce the amount of data on the clipboard and improve the data parsing speed during the pasting process, in the canvas element copy and paste method provided by the present invention, firstly, the canvas element data to be copied is obtained, the canvas element data to be copied is encoded to obtain custom type data, the data type of the canvas element data to be copied is converted to obtain alternative type data, and the custom type data and the alternative type data are stored in the clipboard; then after receiving the paste request, it is determined whether the target paste position supports the custom type data, if it supports the custom type data, the custom type data is parsed and the paste operation is performed, if it does not support the custom type data, the alternative type data is parsed and the paste operation is performed. The present invention reduces the amount of data on the clipboard by encoding the canvas element data to be copied into custom type data, converting the canvas element data to be copied into custom type data and alternative type data respectively, and performing corresponding paste operations according to the data type supported by the target paste position, effectively reducing the time for parsing data and improving user experience.
[0043] In order to better implement the canvas element copy and paste method in the embodiment of the present invention, based on the canvas element copy and paste method, correspondingly, Figure 4 As shown, the present invention also provides a canvas element copy and paste device, and the canvas element copy and paste device 400 includes: A canvas element copying unit 401 is used to obtain canvas element data to be copied, encode the canvas element data to be copied to obtain custom type data, convert the data type of the canvas element data to be copied to obtain candidate type data, and store the custom type data and the candidate type data into a clipboard; The canvas element pasting unit 402 is used to determine whether the target paste position supports custom type data after receiving a paste request. If so, parse the custom type data and perform a paste operation. If not, parse the alternative type data and perform a paste operation.
[0044] The canvas element copy and paste device 400 provided in the above embodiment can implement the technical solution described in the above canvas element copy and paste method embodiment. The specific implementation principles of the above modules or units can refer to the corresponding contents in the above canvas element copy and paste method embodiment, which will not be repeated here.
[0045] like Figure 5 As shown, the present invention also provides an electronic device 500. The electronic device 500 includes a processor 501, a memory 502 and a display 503. Figure 5 Only some components of the electronic device 500 are shown, but it should be understood that it is not required to implement all of the components shown, and more or fewer components may be implemented instead.
[0046] In some embodiments, the processor 501 may be a central processing unit (CPU), a microprocessor or other data processing chip, and is used to run program codes or process data stored in the memory 502, such as the canvas element copy and paste method of the present invention.
[0047] In some embodiments, the processor 501 may be a single server or a server group. The server group may be centralized or distributed. In some embodiments, the processor 501 may be local or remote. In some embodiments, the processor 501 may be implemented in a cloud platform. In one embodiment, the cloud platform may include a private cloud, a public cloud, a hybrid cloud, a community cloud, a distributed cloud, an internal cloud, a multi-cloud, etc., or any combination thereof.
[0048] In some embodiments, the memory 502 may be an internal storage unit of the electronic device 500, such as a hard disk or memory of the electronic device 500. In other embodiments, the memory 502 may also be an external storage device of the electronic device 500, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device 500.
[0049] Furthermore, the memory 502 may include both an internal storage unit of the electronic device 500 and an external storage device. The memory 502 is used to store application software installed in the electronic device 500 and various data.
[0050] In some embodiments, the display 503 may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch device, etc. The display 503 is used to display information of the electronic device 500 and to display a visual user interface. The components 801-803 of the electronic device 500 communicate with each other via a system bus.
[0051] In one embodiment, when the processor 501 executes the canvas element copy and paste program in the memory 502, the following steps may be implemented: Acquire the canvas element data to be copied, perform data encoding on the canvas element data to be copied to obtain custom type data, perform data type conversion on the canvas element data to be copied to obtain candidate type data, and store the custom type data and the candidate type data into the clipboard; After receiving the paste request, determine whether the target paste location supports custom type data. If so, parse the custom type data and perform the paste operation. If not, parse the alternative type data and perform the paste operation.
[0052] It should be understood that: when the processor 501 executes the canvas element copy and paste program in the memory 502, in addition to the above functions, other functions may also be implemented, and details may refer to the description of the corresponding method embodiments above.
[0053] Furthermore, the embodiment of the present invention does not specifically limit the type of the electronic device 500 mentioned, and the electronic device 500 may be a portable electronic device such as a mobile phone, a tablet computer, a personal digital assistant (PDA), a wearable device, a laptop computer, etc. Exemplary embodiments of portable electronic devices include but are not limited to portable electronic devices equipped with IOS, Android, Microsoft or other operating systems. The above-mentioned portable electronic devices may also be other portable electronic devices, such as a laptop computer with a touch-sensitive surface (e.g., a touch panel). It should also be understood that in some other embodiments of the present invention, the electronic device 500 may not be a portable electronic device, but a desktop computer with a touch-sensitive surface (e.g., a touch panel).
[0054] Accordingly, an embodiment of the present application also provides a computer-readable storage medium, which is used to store computer-readable programs or instructions. When the program or instructions are executed by a processor, the steps or functions in the canvas element copy and paste method provided in the above-mentioned method embodiments can be implemented.
[0055] Those skilled in the art will appreciate that all or part of the processes of the above-mentioned embodiments can be implemented by instructing related hardware (such as a processor, a controller, etc.) through a computer program, and the computer program can be stored in a computer-readable storage medium, wherein the computer-readable storage medium is a disk, an optical disk, a read-only storage memory, or a random access memory, etc.
[0056] The canvas element copy and paste method, device, electronic device and storage medium provided by the present invention are introduced in detail above. Specific examples are used in this article to illustrate the principle and implementation mode of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation mode and application scope. In summary, the content of this specification should not be understood as limiting the present invention.
Claims
1. A method for copying and pasting canvas elements, characterized in that: include: Acquire the canvas element data to be copied, perform data encoding on the canvas element data to be copied to obtain user-defined type data, perform data type conversion on the canvas element data to be copied to obtain candidate type data, and store the user-defined type data and the candidate type data into a clipboard; After receiving the paste request, determine whether the target paste position supports the custom type data. If so, parse the custom type data and perform the paste operation. If not, parse the alternative type data and perform the paste operation.
2. The method for copying and pasting canvas elements according to claim 1, characterized in that: The user-defined type data includes canvas element encoding data and encoding type fields.
3. The method for copying and pasting canvas elements according to claim 2, characterized in that: The step of encoding the canvas element data to be copied to obtain the custom type data includes: Performing data format conversion on the canvas element data to be copied to obtain JSON format data, and performing bytecode encoding on the JSON format data to obtain canvas element encoding data; The encoding type of the canvas element encoding data is marked to obtain an encoding type field.
4. The method for copying and pasting canvas elements according to claim 1, characterized in that: The candidate type data includes image type data, and the data type conversion of the to-be-copied canvas element data to obtain the candidate type data includes: The to-be-copied canvas element data is parsed according to a preset image library to generate image type data.
5. The method for copying and pasting canvas elements according to claim 2, characterized in that: The parsing of the user-defined type data and performing a paste operation includes: Determine a corresponding decoding method according to the encoding type field, and decode the canvas element encoding data according to the decoding method to obtain JSON string data; Serialize the JSON string data to obtain the data object to be pasted; Paste the data object to be pasted to the target pasting position.
6. The method for copying and pasting canvas elements according to claim 4, characterized in that: The parsing the candidate type data and performing the paste operation includes: It is determined whether the target paste position supports image type data; if so, the image type data is parsed and a paste operation is performed.
7. The method for copying and pasting canvas elements according to claim 4, characterized in that: The alternative type data also includes text type data, and the method further includes: After receiving the paste request, if the custom type data and the image type data do not exist in the pasteboard, the text type data is parsed and a paste operation is performed.
8. A canvas element copy and paste device, characterized in that: include: A canvas element copying unit, used for obtaining canvas element data to be copied, performing data encoding on the canvas element data to be copied to obtain custom type data, performing data type conversion on the canvas element data to be copied to obtain candidate type data, and storing the custom type data and the candidate type data into a clipboard; The canvas element pasting unit is used to determine whether the target paste position supports the custom type data after receiving the paste request. If the custom type data is supported, the custom type data is parsed and the paste operation is performed; if the custom type data is not supported, the alternative type data is parsed and the paste operation is performed.
9. An electronic device comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the canvas element copying and pasting method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the canvas element copying and pasting method according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Canvas element copying and pasting method and apparatus, electronic device and storage medium
WO2026103584A1