Method for generating personalized font library

By using the diffusion model to train a personalized Chinese character generation model, the time-consuming and labor-intensive problem of traditional font library generation methods is solved, and a personalized font library is quickly and at a low cost is realized to meet the diversified needs in specific Internet scenarios.

CN120218054APending Publication Date: 2025-06-27SHENGQU INFORMATION TECH SHANGHAI
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311813352.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-12-27
Publication Date
2025-06-27

AI Technical Summary

Technical Problem

Traditional font library generation methods require adjusting strokes and spacing one by one, which is time-consuming and labor-intensive, making it difficult to quickly meet the needs of personalized font library in specific Internet scenarios.

Method used

By using Chinese character pictures with a higher frequency in the existing font library as the basic reference structure, combining the target personalized Chinese character pictures, and using a diffusion model (such as DDPM in Unet) for training, a personalized Chinese character generation model is generated, so as to quickly build a personalized font library.

Benefits of technology

It has achieved rapid and low-cost generation of personalized font libraries, meeting the diversified needs in specific Internet scenarios, and reducing time and labor costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120218054A_ABST
    Figure CN120218054A_ABST
Patent Text Reader

Abstract

The invention provides a method for generating a personalized font library. The method comprises the steps that existing Chinese character pictures which are high in use frequency in an existing character library are collected to serve as basic reference structures, Unicode codes of Chinese characters in the pictures are used for naming, and each existing Chinese character picture only has one Chinese character; a plurality of target personalized Chinese character pictures are collected and are named by Unicodes of Chinese characters in the target personalized Chinese character pictures, and each target personalized Chinese character picture only has one Chinese character; and combining the target personalized Chinese character picture with the same Unicode name, the Chinese character picture in the existing character library, the corresponding Unicode name and the corresponding txt annotation file to construct a training sample so as to carry out noise adding training on a diffusion model to obtain a personalized Chinese character generation model. And generating corresponding personalized Chinese character pictures based on the personalized Chinese character generation model so as to construct a personalized character library. By means of the method for generating the personalized font library, the personalized font library can be generated efficiently at low cost, and the personalized requirements of different game scenes for fonts are met.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the application field of generative AI or the field of font library generation, and specifically relates to a method for generating a personalized font library. Background Art

[0002] Currently, in the field of computer text processing, several classic font libraries are usually provided for users to choose from in order to input relevant text information. These classic font libraries include "Song typeface", "Regular script", etc., and the Chinese character styles in each font library are unified. However, with the development of games and large social APPs, more and more users hope to use personalized font libraries for text data in specific scenarios (for example, when transmitting information during large game team formation), thus generating a large demand for personalized font libraries.

[0003] Traditional font library generation methods require software to adjust the strokes, spacing, etc. of each Chinese character in the font library one by one, which requires a considerable amount of time cost and labor cost, and it is difficult to meet the need to quickly and diversely generate personalized font libraries in specific Internet scenarios. Therefore, providing a fast and low-cost method for generating personalized font libraries has practical significance and important commercial value. Summary of the Invention

[0004] In view of this, this application provides a technical solution for generating a personalized font library based on AI technology. It is expected that through the said technical solution, a personalized font library can be generated quickly and at low cost to meet the needs of various network scenarios and various users using personalized font libraries.

[0005] The technical solution provided by the present invention is implemented as a method for generating a personalized font library. The method includes:

[0006] Using the pictures of Chinese characters with higher usage frequencies in the existing font library as the existing Chinese character pictures to construct a basic reference structure, and naming each existing Chinese character picture with the Unicode encoding of the only Chinese character therein; performing stroke annotation on the only Chinese character in each existing Chinese character picture, and saving the annotation results in corresponding stroke annotation files;

[0007] Collecting several target personalized Chinese character pictures, naming them respectively with the Unicode of the Chinese characters therein, and the only Chinese character in each of the target personalized Chinese character pictures exists in the existing Chinese character pictures;

[0008] Combining the target personalized Chinese character pictures with the same Unicode naming and the Chinese character pictures in the existing font library, the corresponding Unicode naming, and the corresponding stroke annotation files to construct a training sample;

[0009] Train a diffusion model based on all the training samples to obtain a personalized Chinese character generation model; based on the personalized Chinese character generation model, generate personalized Chinese character images for constructing a personalized font library.

[0010] Further, the diffusion model is the denoising diffusion model DDPM in Unet. The training of the diffusion model based on all the training samples to obtain a personalized Chinese character generation model includes: inputting each training sample into Unet for forward noise addition training to obtain an intermediate result, and performing backward inference and iterative restoration on the intermediate result; for each Chinese character, when the generated Chinese character image after iterative restoration is visually similar to the corresponding target personalized Chinese character image, the corresponding Unet and related parameters are used as the personalized Chinese character generation model.

[0011] Further, the inputting of each training sample into Unet for forward noise addition training includes: setting the number of steps of forward noise addition, and adding Gaussian noise to the existing Chinese character images in the training samples.

[0012] Further, the stroke annotation of the Chinese characters in each existing Chinese character image is realized as follows: number the 32 strokes used by the Chinese characters from 1 to 32, and each stroke is correspondingly set with a corresponding annotation bit, which is used to annotate the number of times the relevant stroke is used in the unique Chinese character in the existing Chinese character image.

[0013] Preferably, the generating of personalized Chinese character images for constructing a personalized font library based on the personalized Chinese character generation model includes: specifying, through a configuration file, the Chinese character image of the target Chinese character in the existing font library, the Unicode encoding of the corresponding Chinese character, and the stroke annotation file for saving the corresponding Chinese character, and specifying the saving path of the output target personalized Chinese character image; the program inputs the Chinese character image of the target Chinese character in the existing font library, the Unicode encoding of the corresponding Chinese character, and the saved stroke annotation file into the personalized Chinese character generation model based on the configuration file.

[0014] Further, the method further includes: constructing a personalized font library based on all the generated personalized Chinese character images, including: converting the personalized Chinese character images generated by the personalized Chinese character generation model into corresponding svg vector images, and then batch converting the svg vector images into.ttf files through the open-source software FontForge.

[0015] The method for generating a personalized font library provided by the present invention only requires existing Chinese character images (including relevant stroke annotation results) of some Chinese characters with relatively high usage frequencies in the existing font library, as well as a small number of training samples of target personalized Chinese character image components, and then a corresponding personalized Chinese character generation model can be trained. Based on this personalized Chinese character generation model, a corresponding personalized font library can be constructed quickly and at low cost to meet various application scenarios in a timely manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] To more clearly illustrate the technical solutions of the embodiments of the present application, the accompanying drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present application and should not be regarded as limiting the scope. For those of ordinary skill in the art, other relevant drawings can be obtained based on these drawings without creative efforts.

[0017] Figure 1 FIG. is a schematic flowchart of the method for generating a personalized font library provided by the present invention in one embodiment.

[0018] Figure 2 FIG. is a coding list of 32 strokes used for stroke standardization of Chinese characters in the present invention in one embodiment.

[0019] Figure 3 Based on Figure 2 the stroke annotation results of some Chinese characters shown in the stroke coding list. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0020] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. The components of the embodiments of the present application described and illustrated in the drawings here can be arranged and designed in various different configurations. Therefore, the detailed description of the embodiments of the present application provided in the drawings below is not intended to limit the scope of the present application to be protected, but only represents the selected embodiments of the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present application without creative efforts fall within the scope of protection of the present application.

[0021] It should be noted that: similar reference numerals and letters denote similar items in the following drawings. Therefore, once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. At the same time, in the description of the present application, the terms "first", "second", etc. are only used for distinguishing descriptions and cannot be understood as indicating or implying relative importance.

[0022] Such as Figure 1As shown, in one embodiment, the method for generating a personalized font library provided by the present invention includes the following steps:

[0023] S1. Use the pictures of Chinese characters with relatively high usage frequencies in the existing font library as the existing Chinese character pictures to construct a basic reference structure. Each existing Chinese character picture is named with the Unicode encoding of the unique Chinese character therein; perform stroke annotation on the unique Chinese character in each existing Chinese character picture, and save the annotation results in corresponding stroke annotation files.

[0024] For example, in step S1, first generate 3500 common Chinese character pictures (i.e., existing Chinese character pictures) using a set of standard common printing fonts to serve as the basic reference structure; these pictures themselves represent the content. Each of these Chinese character pictures is named with the Unicode encoding number of the unique Chinese character therein. Then perform stroke annotation on these Chinese character pictures and save them as txt documents. The stroke annotation is based on Figure 2 the 32 Chinese character strokes shown in. The stroke annotation can be implemented as follows: number the 32 types of strokes used in Chinese characters from 1 to 32, and each type of stroke is correspondingly provided with a corresponding annotation bit for annotating the number of times the relevant stroke is used in the unique Chinese character of the existing Chinese character picture (annotate the number of times this stroke is used, and annotate 0 if it is not used). The stroke annotation results of some Chinese characters are as shown in Figure 3 shown.

[0025] S2. Collect a number of target personalized Chinese character pictures, and name them respectively with the Unicode of the Chinese characters therein. The unique Chinese character in each of the target personalized Chinese character pictures exists in the existing Chinese character pictures. Here, we need to collect a number of target personalized Chinese character pictures for reference and comparison when training relevant neural network models. For example, 100 or 200 target personalized Chinese character pictures with different Chinese characters can be collected for subsequent construction of training samples.

[0026] S3. Combine the target personalized Chinese character pictures with the same Unicode naming, the Chinese character pictures in the existing font library, the corresponding Unicode naming, and the corresponding stroke annotation files to construct training samples.

[0027] S4. Train a diffusion model based on all the training samples to obtain a personalized Chinese character generation model. Among them, the Chinese character pictures in the existing font library with the same Unicode naming as the target personalized Chinese character pictures, the corresponding Unicode naming, and the corresponding stroke annotation files are spliced together and fed into the diffusion model for deep learning. The corresponding target personalized Chinese character pictures are used to visually compare the similarity with the Chinese character pictures output during the model training iteration.

[0028] Further, the diffusion model is the denoising diffusion model DDPM in Unet. Training the diffusion model based on all the training samples to obtain a personalized Chinese character generation model includes: inputting each training sample into Unet for forward noise addition training to obtain intermediate results (including: setting the number of steps for forward noise addition, adding Gaussian noise to the existing Chinese character images in the training samples), and performing reverse inference and iterative restoration on the intermediate results; for each Chinese character, when the iteratively restored Chinese character image and the corresponding target personalized Chinese character image reach a visually similar degree (achieved by adjusting the number of iterations), the corresponding Unet and related parameters are used as the personalized Chinese character generation model.

[0029] S5. Based on the personalized Chinese character generation model, generate personalized Chinese character images for constructing a personalized font library. This step can be implemented as follows: specify the Chinese character image of the target Chinese character in the existing font library, the Unicode encoding of the corresponding Chinese character, and the stroke annotation file for saving the corresponding Chinese character through a configuration file, and specify the saving path of the output target personalized Chinese character image; the program inputs the Chinese character image of the target Chinese character in the existing font library, the Unicode encoding of the corresponding Chinese character, and the saved stroke annotation file into the personalized Chinese character generation model based on the configuration file.

[0030] For example, in Python, use the load_checkpoint function to load the personalized Chinese character generation model in the.pt file format generated by training, and at the same time input the target characters in the existing font library for which personalized Chinese characters need to be generated. The target characters in the existing font library can be loaded by creating a.yaml configuration file, and the.yaml file can be loaded by importing the yaml library using import yaml. Of course, the saving path of the generated personalized Chinese character images can also be specified in the yaml configuration file.

[0031] Further, the method further includes: constructing a personalized font library based on all the generated personalized Chinese character images, including: converting the personalized Chinese character images generated by the personalized Chinese character generation model into corresponding svg vector graphics, and then batch converting the svg vector graphics into.ttf files through the open-source software FontForge. Specifically, it can be achieved through the following steps:

[0032] 1. Use the opencv library in Python to convert the generated personalized Chinese character images into svg vector graphics. 01. Use the import command to import the opencv and os libraries:

[0033] import cv2;

[0034] import os;

[0035] 02. Use img_list = os.listdir(image path) to obtain all personalized Chinese character images in Python and report them as a list.

[0036] 03. Then, in the for loop, use the command cv2.imread to convert the images to grayscale images (os.path.join(img_list of the current loop), cv2.IMREAD_COLOR). Use OpenCV to open all personalized Chinese character images at once. Define the screen size using cv2.resize, define the blurred edge size using cv2.GaussianBlur, and use cv2.cvtColor(blur, cv2.COLOR_BGR2GRAY). Use cv2.threshold to binarize the images to extract the Chinese character area, and then use cv2.findContours to draw the text outline. Then define an svg format <svg version = "1.0" xmlns = "http: / / www.w3.org / 2000 / svg" width = "{w*0.1}.000000pt" height = "{h*0.1}.000000pt" viewBox = "0 0 1024.000000 1024.000000" preserveAspectRatio = "xMidYMid meet">'). Draw a vector curve along the outline using cv2.approxPolyDP, and finally save the information of the vector curve into the defined svg container to save the svg file.

[0037] 2. Batch import the svg vector images into the open-source software FontForge to generate.tff format files.

[0038] 021. Create a new font in the Python program through fontforge.font() (equivalent to creating a blank document in Word).

[0039] 022. Set the name of the new font using font.fondname, such as: Qu Xiaoyao Song.

[0040] 023. In the for loop, read the svg vector images just saved one by one. Create Chinese character glyphs through the svg name (unicode encoded number). The code is font.createChar("uni" + svg name); then import the vector image into the currently created Chinese character glyph through glyph.importOutlines(os.path.join(svg vector image full path)).

[0041] 024. After debugging various information such as kerning, line spacing, copyright, etc. in FontForge, finally export the.ttf file.

[0042] As described above, it is only the specific implementation manner of this application, but the protection scope of this application is not limited thereto. Any person skilled in the art within the technical scope disclosed by this application can easily think of changes or substitutions, which should all be covered within the protection scope of this application. Therefore, the protection scope of this application should be subject to the protection scope of the claims.

Claims

1. A method for generating a personalized font library, characterized in that, The method includes: Taking pictures of Chinese characters with high usage frequencies in the existing font library as existing Chinese character pictures to construct a basic reference structure, and naming each existing Chinese character picture with the Unicode encoding of the only Chinese character therein; performing stroke annotation on the only Chinese character in each existing Chinese character picture, and saving the annotation results in corresponding stroke annotation files; Collecting a number of target personalized Chinese character pictures, naming them respectively with the Unicode of the Chinese characters therein, and the only Chinese character in each of the target personalized Chinese character pictures exists in the existing Chinese character pictures; Combining the target personalized Chinese character pictures with the same Unicode naming as the Chinese character pictures in the existing font library, the corresponding Unicode naming, and the corresponding stroke annotation files to construct training samples; Training a diffusion model based on all the training samples to obtain a personalized Chinese character generation model; Generating personalized Chinese character pictures for constructing a personalized font library based on the personalized Chinese character generation model.

2. The method according to claim 1, wherein The diffusion model is the denoising diffusion model DDPM in Unet.

3. The method according to claim 2, wherein The stroke annotation of the Chinese characters in each existing Chinese character picture is realized as follows: numbering the 32 strokes used by the Chinese characters from 1 to 32, and each stroke is correspondingly provided with a corresponding annotation bit for annotating the number of times the relevant stroke is used in the only Chinese character in the existing Chinese character picture.

4. The method according to claim 3, wherein The training of the diffusion model based on all the training samples to obtain a personalized Chinese character generation model includes: Inputting each training sample into Unet for forward noise addition training to obtain an intermediate result, and performing backward inference and iterative restoration on the intermediate result; for each Chinese character, when the iteratively restored Chinese character picture reaches a visually similar degree to the corresponding target personalized Chinese character picture, the corresponding Unet and related parameters are used as the personalized Chinese character generation model.

5. The method according to claim 4, wherein The inputting of each training sample into Unet for forward noise addition training includes: setting the number of steps of forward noise addition, and adding Gaussian noise to the existing Chinese character pictures in the training samples.

6. The method according to any one of claims 1-5, characterized in that, Generating personalized Chinese character pictures for constructing a personalized font library based on the personalized Chinese character generation model includes: specifying the Chinese character pictures of the target Chinese characters in the existing font library, the Unicode encoding of the corresponding Chinese characters, and the stroke annotation files for saving the corresponding Chinese characters through a configuration file, and specifying the saving path of the output target personalized Chinese character pictures; the program inputs the Chinese character pictures of the target Chinese characters in the existing font library, the Unicode encoding of the corresponding Chinese characters, and the stroke annotation files for saving the corresponding Chinese characters into the personalized Chinese character generation model based on the configuration file.

7. The method according to any one of claims 1-5, characterized in that, The method further includes: constructing a personalized font library based on all the generated personalized Chinese character pictures, including: converting the personalized Chinese character pictures generated by the personalized Chinese character generation model into corresponding svg vector graphics, and then batch converting the svg vector graphics into.ttf files through the open-source software FontForge.