Subtitle rendering method, device, equipment, and computer-readable storage medium
By obtaining and judging the typesetting method and font support in the subtitle data, the SVG glyph expression string is generated, which solves the problem of low subtitle rendering accuracy, especially in vertical typesetting, ensuring the correct rendering effect of the subtitles.
Patent Information
- Application Number
- CN202110556251.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-20
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2041-05-20
AI Technical Summary
The rendering accuracy of subtitles is low, especially when typesetting vertically. Due to font file design flaws, third-party rendering tools cannot correctly identify and render vertical writing, resulting in incorrect display effects.
By obtaining the subtitle data to be rendered, determine the typesetting method of the words to be rendered. If it is vertical typesetting, determine its support for vertical writing, and obtain or generate the corresponding scalable vector graphic SVG glyph expression string for rendering to ensure correctness. Vertical layout display.
It improves the accuracy of subtitle rendering, avoids the problem of vertical typesetting fonts being incorrectly rendered into horizontal typesetting due to font files, and ensures the correct display of subtitles.
Smart Images

Figure CN113326677B
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing, and in particular to a subtitle rendering method and apparatus, device, and computer-readable storage medium. Background Art
[0002] With the further evolution of subtitle specifications, the importance of subtitles in current multimedia playback has become increasingly prominent. Whether it is the CEA / EIA608-708 standard or other standards such as the TTML2 standard, they can be rendered through third-party rendering tools that the subtitle rendering module relies on to achieve the display effect that the subtitles want to express.
[0003] It is understandable that there are two types of subtitle typesetting methods: horizontal typesetting and vertical typesetting. Among them, in the vertical typesetting of subtitles, in addition to the need for the typeset glyphs of this form to exist in the font file, the design of the font file must also be correctly identified and referenced by the third-party rendering tool. When there are defects in the font file design, such as the vertical and horizontal forms of the same word using different encoding values, or using the same encoding value but lacking field information to distinguish between the two, the third-party rendering tool will be unable to render the correct vertical typesetting display effect according to the provided font file.
[0004] Therefore, how to improve the accuracy of subtitle rendering is an urgent problem to be solved. Summary of the invention
[0005] The main purpose of this application is to provide a subtitle rendering method and device, equipment, and computer-readable storage medium, aiming to solve the problem of low subtitle rendering accuracy in related technologies.
[0006] To achieve the above object, the present application provides a subtitle rendering method, the subtitle rendering method comprising:
[0007] Get the subtitle data to be rendered;
[0008] Determining the layout of the characters to be rendered according to the subtitle data to be rendered;
[0009] If the typesetting mode of the character to be rendered is vertical typesetting, determining whether the character to be rendered supports vertical writing;
[0010] If the character to be rendered supports vertical writing, a scalable vector graphics SVG glyph expression string of the vertical writing form of the character to be rendered is obtained, and the character to be rendered is rendered according to the SVG glyph expression string.
[0011] Optionally, if the typesetting mode of the character to be rendered is vertical typesetting, the step of determining whether the character to be rendered supports vertical writing includes:
[0012] If the typesetting mode of the character to be rendered is vertical typesetting, determining the encoding value of the character to be rendered;
[0013] According to the encoding value of the to-be-rendered character, determining whether the to-be-rendered character is included in the SVG font file;
[0014] If it is included, it is determined that the character to be rendered supports vertical writing;
[0015] If not, it is determined that the character to be rendered does not support vertical writing;
[0016] The SVG font file has preset therein a plurality of SVG glyph expression strings of characters supporting vertical writing, and encoding values of the characters supporting vertical writing in the encoding character set.
[0017] Optionally, if the typesetting mode of the to-be-rendered characters is vertical typesetting, before the step of determining the encoding value of the to-be-rendered characters, the subtitle rendering method further includes:
[0018] Determine the font type of the word to be rendered;
[0019] According to the font type, the SVG font file corresponding to the font type is determined.
[0020] Optionally, if the typesetting mode of the to-be-rendered characters is vertical typesetting, before the step of determining the encoding value of the to-be-rendered characters, the subtitle rendering method further includes:
[0021] Convert TTF font files to SVG font intermediate files;
[0022] Obtaining SVG glyph expression strings of all characters supporting vertical writing from the SVG font intermediate file;
[0023] The SVG font file is generated according to the SVG glyph expression string of the character supporting vertical writing and the encoding value corresponding to the character supporting vertical writing in the encoding character set.
[0024] Optionally, the step of determining the layout of the characters to be rendered according to the subtitle data to be rendered includes:
[0025] Acquire subtitle text information and subtitle layout information from the subtitle data to be rendered;
[0026] Determine the word to be rendered according to the subtitle text information;
[0027] The typesetting mode of the characters to be rendered is determined according to the subtitle typesetting information.
[0028] Optionally, after the step of determining the layout of the characters to be rendered according to the subtitle data to be rendered, the subtitle rendering method further comprises the following steps:
[0029] If the typesetting mode of the character to be rendered is horizontal typesetting, obtaining a TTF glyph expression string of the character to be rendered;
[0030] Render the to-be-rendered character according to the TTF character expression string.
[0031] Optionally, if the typesetting mode of the to-be-rendered characters is vertical typesetting, after the step of determining the support status of the to-be-rendered characters for vertical writing, the subtitle rendering method further comprises the following steps:
[0032] If the typesetting mode of the character to be rendered is vertical typesetting, and the character to be rendered does not support vertical writing, then obtaining a TTF glyph expression string of the character to be rendered;
[0033] Render the to-be-rendered character according to the TTF character expression string.
[0034] Optionally, if the typesetting mode of the character to be rendered is horizontal typesetting, the step of obtaining the TTF glyph expression string of the character to be rendered includes:
[0035] If the typesetting mode of the character to be rendered is horizontal typesetting, determining the encoding value of the character to be rendered;
[0036] According to the encoding value of the character to be rendered, a TTF glyph expression string in horizontal form of the character to be rendered is obtained from a TTF font file; wherein the TTF font file presets a plurality of TTF glyph expression strings of characters supporting horizontal form and vertical form, and the encoding values of the characters supporting horizontal form and vertical form in a coded character set.
[0037] Optionally, if the typesetting mode of the character to be rendered is vertical typesetting, but the character to be rendered does not support vertical writing, the step of obtaining the TTF glyph expression string of the character to be rendered includes:
[0038] If the character to be rendered does not support vertical writing, determining the encoding value of the character to be rendered;
[0039] According to the encoding value of the character to be rendered, a TTF glyph expression string of the vertical writing form of the character to be rendered is obtained from the TTF font file; wherein the TTF font file presets a plurality of TTF glyph expression strings of characters supporting horizontal form and vertical form, and the encoding values of the characters supporting horizontal form and vertical form in the encoding character set.
[0040] In addition, to achieve the above-mentioned purpose, the present application also proposes a subtitle rendering device, the subtitle rendering device comprising:
[0041] A first acquisition module, used to acquire subtitle data to be rendered;
[0042] A determination module, used for determining the layout mode of the characters to be rendered according to the subtitle data to be rendered;
[0043] A second acquisition module is used for acquiring a scalable vector graphic SVG glyph expression string of the vertical writing form of the character to be rendered if the typesetting mode of the character to be rendered is vertical typesetting and supports vertical form;
[0044] A rendering module is used to render the to-be-rendered character according to the SVG character expression string.
[0045] In addition, to achieve the above-mentioned purpose, the present application also proposes a subtitle rendering device, which includes: a memory, a processor, and a subtitle rendering program stored in the memory and running on the processor, and when the subtitle rendering program is executed by the processor, the steps of the subtitle rendering method described above are implemented.
[0046] In addition, to achieve the above-mentioned purpose, the present application also proposes a computer-readable storage medium, on which a subtitle rendering program is stored. When the subtitle rendering program is executed by a processor, the steps of the subtitle rendering method described above are implemented.
[0047] The technical solution provided by the present application obtains the subtitle data to be rendered, and determines the typesetting mode of the characters to be rendered according to the obtained subtitle data to be rendered, wherein if the typesetting mode of the characters to be rendered is vertical typesetting, then the support of the characters to be rendered for the vertical writing form is determined, and if the characters to be rendered support the vertical writing form, then the scalable vector graphic SVG glyph expression string of the vertical writing form of the characters to be rendered is obtained, and the characters to be rendered are rendered according to the SVG glyph expression string; the problem of low accuracy of subtitle rendering in the related art is solved. That is, in the technical solution provided by the present application, when the characters to be rendered are vertically typeset and support the vertical writing form, they are rendered according to the SVG glyph expression string corresponding to the characters to be rendered, thereby achieving the correct rendering of the characters to be rendered as a vertical typesetting display effect, avoiding the phenomenon that the third-party rendering tool always renders the characters to be rendered that can be typeset vertically as a horizontal typesetting display due to font file factors, and improving the accuracy of subtitle rendering. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the structures shown in these drawings without paying any creative work.
[0049] Figure 1 It is a schematic diagram of the structure of a subtitle rendering device in a hardware operating environment involved in an embodiment of the present application;
[0050] Figure 2 This is a flowchart of the first embodiment of the subtitle rendering method of the present application;
[0051] Figure 3 This is a flow chart of the second embodiment of the subtitle rendering method of the present application;
[0052] Figure 4 This is a flowchart of the third embodiment of the subtitle rendering method of the present application;
[0053] Figure 5-1 This is an interface diagram of the fourth embodiment of the subtitle rendering method of this application Figure 1 ;
[0054] Figure 5-2 This is an interface diagram of the fourth embodiment of the subtitle rendering method of this application Figure 2 ;
[0055] Figure 5-3 This is an interface diagram of the fourth embodiment of the subtitle rendering method of this application Figure 3 ;
[0056] Figure 6 This is a structural block diagram of the first embodiment of the subtitle rendering device of the present application.
[0057] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0058] It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0059] See also Figure 1 As shown, Figure 1 This is a schematic diagram of the structure of a subtitle rendering device in the hardware operating environment involved in the embodiment of the present application.
[0060] The subtitle rendering device includes: at least one processor 101, a memory 102, and a subtitle rendering program stored in the memory and executable on the processor, wherein the subtitle rendering program is configured to implement the steps of the subtitle rendering method of any of the following embodiments.
[0061] The processor 101 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 101 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 101 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 101 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. The processor 101 may also include an AI (Artificial Intelligence) processor, which is used to process operations related to the subtitle rendering method, so that the subtitle rendering method model can be trained and learned autonomously to improve efficiency and accuracy.
[0062] The memory 102 may include one or more computer-readable storage media, which may be non-transitory. The memory 102 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage subtitle rendering devices, flash storage subtitle rendering devices. In some embodiments, the non-transitory computer-readable storage medium in the memory 102 is used to store at least one instruction, which is used to be executed by the processor 101 to implement the subtitle rendering method provided in the method embodiment of the present application.
[0063] In some embodiments, the subtitle rendering device may further optionally include: a communication interface 103 and at least one peripheral device. The processor 101, the memory 102 and the communication interface 103 may be connected via a bus or a signal line. Each peripheral device may be connected to the communication interface 103 via a bus, a signal line or a circuit board. Specifically, the peripheral device includes: at least one of a radio frequency circuit 104, a display screen 105 and a power supply 106.
[0064] The communication interface 103 may be used to connect at least one peripheral device related to I / O (Input / Output) to the processor 101 and the memory 102. In some embodiments, the processor 101, the memory 102, and the communication interface 103 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 101, the memory 102, and the communication interface 103 may be implemented on a separate chip or circuit board, which is not limited in this embodiment.
[0065] The radio frequency circuit 104 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The radio frequency circuit 104 communicates with the communication network and other communication subtitle rendering devices through electromagnetic signals. The radio frequency circuit 104 converts the electrical signal into an electromagnetic signal for transmission, or converts the received electromagnetic signal into an electrical signal. Optionally, the radio frequency circuit 104 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, and the like. The radio frequency circuit 104 can communicate with other terminals through at least one wireless communication protocol. The wireless communication protocol includes, but is not limited to: a metropolitan area network, various generations of mobile communication networks (2G, 3G, 4G and 5G), a wireless local area network and / or a WiFi (Wireless Fidelity) network. In some embodiments, the radio frequency circuit 104 may also include circuits related to NFC (Near Field Communication), which is not limited in this application.
[0066] The display screen 105 is used to display a UI (User Interface). The UI may include graphics, text, icons, videos, and any combination thereof. When the display screen 105 is a touch display screen, the display screen 105 also has the ability to collect touch signals on the surface or above the surface of the display screen 105. The touch signal can be input to the processor 101 as a control signal for processing. At this time, the display screen 105 can also be used to provide virtual buttons and / or virtual keyboards, also known as soft buttons and / or soft keyboards. In some embodiments, the display screen 105 can be one, the front panel of the subtitle rendering device; in other embodiments, the display screen 105 can be at least two, respectively arranged on different surfaces of the subtitle rendering device or in a folding design; in some embodiments, the display screen 105 can be a flexible display screen, arranged on a curved surface or a folding surface of the subtitle rendering device. Even, the display screen 105 can also be set to a non-rectangular irregular shape, that is, a special-shaped screen. The display screen 105 can be made of materials such as LCD (Liquid Crystal Display), OLED (Organic Light-Emitting Diode, organic light-emitting diode).
[0067] The power supply 106 is used to power various components in the subtitle rendering device. The power supply 106 can be an alternating current, a direct current, a disposable battery, or a rechargeable battery. When the power supply 106 includes a rechargeable battery, the rechargeable battery can support wired charging or wireless charging. The rechargeable battery can also be used to support fast charging technology.
[0068] Those skilled in the art will understand that Figure 1 The structure shown in the figure does not constitute a limitation on the subtitle rendering device, and may include more or less components than those shown in the figure, or combine certain components, or arrange the components differently.
[0069] Based on the above hardware structure, various embodiments of the present application are proposed.
[0070] See also Figure 2 As shown, Figure 2 This is a flowchart of the first embodiment of the subtitle rendering method of the present application. The subtitle rendering method includes the following steps:
[0071] Step S201: Obtain subtitle data to be rendered.
[0072] In this embodiment, the subtitle data to be rendered refers to relevant data involved in rendering subtitles to display on a display screen. Optionally, the subtitle data to be rendered includes but is not limited to subtitle text information and subtitle layout information.
[0073] The subtitle text information refers to the subtitle body waiting to be rendered, which includes at least one word to be rendered. Optionally, the word to be rendered includes but is not limited to text, letters, symbols, etc. The text can be Chinese, Japanese, Korean, etc.
[0074] Among them, the subtitle layout information refers to the layout method of the subtitles waiting to be rendered, also expressed as writing-mode. It can be understood that the layout method includes horizontal layout and vertical layout. Optionally, the common horizontal layout refers to the horizontal layout from left to right and from top to bottom, also expressed as lrtb; the common vertical layout refers to the vertical layout from top to bottom and from right to left, also expressed as tbrl.
[0075] In some examples, the subtitle data to be rendered can be obtained at preset time intervals, which can save system consumption and avoid power waste. For example, the subtitle data to be rendered can be obtained every 20ms. In actual applications, the preset time period can be flexibly adjusted according to the specific application scenario.
[0076] In some examples, the subtitle data to be rendered can be acquired in real time, that is, there is no need to acquire it at intervals, which can improve the immediacy of acquiring the subtitle data to be rendered, improve rendering efficiency, etc.
[0077] Step S202: Determine the layout of the characters to be rendered according to the subtitle data to be rendered.
[0078] In this embodiment, the step of determining the layout of the characters to be rendered according to the subtitle data to be rendered may include the following steps:
[0079] First, obtain subtitle text information and subtitle layout information from the subtitle data to be rendered;
[0080] Then, determine the words to be rendered according to the subtitle text information;
[0081] Secondly, the layout of the characters to be rendered is determined according to the subtitle layout information.
[0082] That is, in this embodiment, step S202 determines the layout of the characters to be rendered according to the subtitle data to be rendered, which can be specifically achieved by first obtaining subtitle text information and subtitle layout information from the subtitle data to be rendered, then determining the characters to be rendered according to the subtitle text information, and then determining the layout of the characters to be rendered according to the subtitle layout information. Among them, the step of determining the characters to be rendered according to the subtitle text information and the step of determining the layout of the characters to be rendered according to the subtitle layout information can be executed in parallel or in any order; in actual applications, they can be flexibly adjusted according to specific application scenarios.
[0083] For example, first obtain the subtitle text information a1 and the subtitle layout information a2 from the subtitle data A to be rendered, then determine from the subtitle text information a1 that the eight words to be rendered are "I go home immediately after get off work", and then determine from the subtitle layout information a2 that the layout method of the eight words to be rendered "I go home immediately after get off work" is all vertical layout.
[0084] It can be understood that in this embodiment, determining the typesetting method of the characters to be rendered based on the subtitle data to be rendered includes two situations; among them, in the first situation, according to the subtitle data to be rendered, determining the typesetting method of the characters to be rendered is vertical typesetting, and in the second situation, according to the subtitle data to be rendered, determining the typesetting method of the characters to be rendered is horizontal typesetting.
[0085] Step S203: If the typesetting mode of the character to be rendered is vertical typesetting, then determining whether the character to be rendered supports vertical writing.
[0086] In this embodiment, no matter whether the typesetting mode of the characters to be rendered is determined to be vertical typesetting or horizontal typesetting according to the subtitle data to be rendered, it is necessary to determine whether the characters to be rendered support vertical writing.
[0087] In this embodiment, if the typesetting mode of the character to be rendered is vertical typesetting, the step of determining the support status of the character to be rendered for the vertical writing form may include the following steps:
[0088] First, if the typesetting mode of the character to be rendered is vertical typesetting, the encoding value of the character to be rendered is determined;
[0089] Then,
[0090] If the character to be rendered is found in the SVG font file according to the encoding value of the character to be rendered, it is determined that the character to be rendered supports the vertical writing form;
[0091] If the character to be rendered is not found in the SVG font file according to the encoding value of the character to be rendered, it is determined that the character to be rendered does not support vertical writing.
[0092] That is, in step S203 of the present embodiment, if the typeset mode of the character to be rendered is vertical typeset, then the support status of the character to be rendered for the vertical writing form is determined. Specifically, the support status of the character to be rendered for the vertical writing form can be achieved by first determining the encoding value of the character to be rendered. If the character to be rendered can be found in the SVG font file according to the encoding value of the character to be rendered, then it is determined that the character to be rendered supports the vertical writing form. If the character to be rendered cannot be found in the SVG font file according to the encoding value of the character to be rendered, then it is determined that the character to be rendered does not support the vertical writing form.
[0093] It should be clear that, in this embodiment, the SVG font file has preset therein a plurality of SVG glyph expression strings of characters supporting vertical writing, and encoding values of the characters supporting vertical writing in the encoding character set.
[0094] Among them, the coded character set refers to a standard coded character set that meets international standards. For example, the coded character set can be UTF-8 (8-bit, Universal Character Set / Unicode Transformation Format), or it can be Unicode (also known as Unicode, Universal Code, Single Code), etc. It can be understood that UTF-8 is a variable-length character encoding for Unicode, which can be used to represent any character in the Unicode standard, and the first byte in its encoding is still compatible with ASCII, so that the original software that processes ASCII characters can continue to be used without or with only a few modifications. Unicode includes coded character sets, encoding schemes, etc., which are created to solve the limitations of traditional character encoding schemes. It sets a unified and unique binary encoding for each character in each language to meet the requirements of text conversion and processing across languages and platforms.
[0095] Among them, the specific character can be determined according to the encoding value corresponding to the encoding character set; for example, the character "《", if its corresponding encoding character set is UTF-8, then the corresponding value is E3808A, and if its corresponding encoding character set is Unicode, then the corresponding value is 《.
[0096] For example, if it is determined that the encoding value corresponding to the character to be rendered is k1, then a search is performed in the SVG font file according to the encoding value k1 corresponding to the character to be rendered. If the encoding value k1 is found, it can be determined that the character to be rendered supports vertical writing. If the encoding value k1 is not found, it can be determined that the character to be rendered does not support vertical writing.
[0097] In this embodiment, if the layout of the characters to be rendered is vertical layout, before the step of determining the encoding value of the characters to be rendered, the subtitle rendering method may further include the following steps:
[0098] First, convert the TTF font file to an SVG font intermediate file;
[0099] Then, obtain the SVG glyph expression strings of all characters that support vertical writing from the SVG font intermediate file;
[0100] Secondly, an SVG font file is generated according to the SVG glyph expression string of the characters supporting vertical writing and the encoding values corresponding to the characters supporting vertical writing in the encoding character set.
[0101] That is, before the step of determining the support status of the to-be-rendered character for the vertical writing form according to the SVG font file in this embodiment, the SVG font file needs to be generated first.
[0102] In some examples, see Table 1, which is an example SVG font file.
[0103] Table 1
[0104]
[0105] In the above Table 1, only two glyph SVG expressions are illustrated, wherein the encoding character set is UTF-8, and the SVG expression includes the glyph name glyph-name, unicode, and the SVG glyph expression string d.
[0106] In some examples, see Table 2, which is an example SVG font file.
[0107] Table 2
[0108]
[0109]
[0110] In the above Table 2, only two glyphs' SVG expressions are exemplified, wherein the coded character set is Unicode, and the SVG expression includes the glyph name glyph-name, unicode, and the SVG glyph expression string d.
[0111] Among them, the SVG font file generated in this embodiment may also contain other content besides the corresponding values of the coded character set that supports vertical writing, and the SVG glyph expression string; in actual applications, the content contained in the SVG font file can be flexibly adjusted according to the specific application scenario.
[0112] It should be noted that the SVG glyph set information contained in the SVG font file generated in this embodiment can be imported into the corresponding project file, so that the rendering module can easily find / acquire it; it can also be directly modified by external import when external characters need to be expanded, without modifying the project file itself, with high reusability and strong maintainability.
[0113] In this embodiment, if the layout of the characters to be rendered is vertical layout, before the step of determining the encoding value of the characters to be rendered, the subtitle rendering method may further include the following steps:
[0114] First, determine the font type of the word to be rendered;
[0115] Then, according to the font type, the SVG font file corresponding to the font type is determined.
[0116] It can be understood that since different font types correspond to different SVG font files; therefore, in order to improve the accuracy of determining the support of the vertical writing form for the characters to be rendered, before the step of determining the support of the vertical writing form for the characters to be rendered according to the SVG font file in this embodiment, it is also necessary to first determine the font type of the characters to be rendered, and then determine the SVG font file corresponding to the font type according to the font type of the characters to be rendered; in this way, after finding the SVG font file corresponding to the correct font type, it is possible to determine the support of the vertical writing form for the characters to be rendered according to the correct SVG font file.
[0117] In some examples, see Table 3, which is an example SVG font file.
[0118] Table 3
[0119]
[0120]
[0121] In the above Table 3, only two font types are exemplified. In actual applications, the font type can be flexibly adjusted according to the specific application scenario; one of them can correspond to one SVG font file, which only needs to be divided according to different font types, as shown in the above Table 3; or it can correspond to multiple SVG font files, and it is only necessary to divide the SVG glyph expression strings corresponding to the characters of the same font type into the same SVG font file.
[0122] In this embodiment, by distinguishing different font types to generate the same but classified SVG font file, or by generating different SVG font files, it is possible to more efficiently determine the support of the vertical writing form for the characters to be rendered according to the SVG font file; and it is possible to determine the SVG glyph expression string for characters of different font types, thereby ensuring that characters of different font types can all be correctly rendered as vertical typeset display effects, further improving the accuracy of subtitle rendering.
[0123] Step S204: If the character to be rendered supports vertical writing, a scalable vector graphic SVG glyph expression string of the vertical writing form of the character to be rendered is obtained, and the character to be rendered is rendered according to the SVG glyph expression string.
[0124] In this embodiment, if the character to be rendered supports vertical writing, it is necessary to obtain a scalable vector graphics SVG (Scalable Vector Graphics) glyph expression string of the character to be rendered, so as to render the character to be rendered according to the SVG glyph expression string of the character to be rendered, thereby realizing the display of the rendered character.
[0125] In this embodiment, the step of obtaining a scalable vector graphic SVG glyph expression string of the vertical writing form of the character to be rendered can be specifically achieved by searching the character to be rendered from the SVG font file according to the encoding value of the character to be rendered, and obtaining the corresponding SVG glyph expression string.
[0126] In this embodiment, the step of rendering the characters to be rendered according to the SVG glyph expression string may specifically be that the subtitle rendering module draws the SVG glyph expression string according to the drawPath function of the third-party rendering tool skia, thereby rendering the characters to be rendered.
[0127] In the present embodiment, when it is obtained that the typesetting mode of the characters to be rendered is vertical typesetting and the characters to be rendered support vertical writing, the SVG glyph expression string of the characters to be rendered is determined according to the SVG font file, and then the SVG glyph expression string is drawn according to the drawPath function; the rendering of the characters to be rendered in vertical typesetting is realized, and the phenomenon that the characters to be rendered in vertical typesetting are always based on the TTF font file and are mistakenly rendered as horizontal typesetting display is avoided, thereby improving the accuracy of subtitle rendering; and the original TTF font file is not modified, and the copyright of the original TTF font file is not infringed, and the rendering logic is simple, the program complexity is low, and it is easy to implement.
[0128] Based on the above embodiments, a second embodiment of the subtitle rendering method of the present application is proposed.
[0129] See also Figure 3 As shown, Figure 3 This is a flow chart of the second embodiment of the subtitle rendering method of the present application; in this embodiment, after step S202 determines the typesetting method of the to-be-rendered characters according to the to-be-rendered subtitle data, the subtitle rendering method may further include the following steps:
[0130] Step S205: If the typesetting mode of the character to be rendered is horizontal typesetting, a TTF glyph expression string of the character to be rendered is obtained, and the character to be rendered is rendered according to the TTF glyph expression string.
[0131] In some examples, if the typesetting mode of the character to be rendered is horizontal typesetting, the step of obtaining the TTF glyph expression string of the character to be rendered in step S205 may include the following steps:
[0132] First, if the typesetting mode of the character to be rendered is horizontal typesetting, the encoding value of the character to be rendered is determined;
[0133] Then, according to the encoding value of the character to be rendered, a TTF glyph expression string of the horizontal writing form of the character to be rendered is obtained from the TTF font file.
[0134] That is, in step S205 of the present embodiment, if the typeset mode of the character to be rendered is horizontal typeset, then the TTF glyph expression string of the character to be rendered is obtained. Specifically, this can be achieved by first determining the encoding value of the character to be rendered, and then obtaining the TTF glyph expression string of the character to be rendered in horizontal form from the TTF font file according to the encoding value of the character to be rendered.
[0135] It should be clear that the TTF font file in this embodiment pre-sets multiple TTF glyph expression strings that support characters in horizontal and vertical forms, as well as the encoding values of the characters that support characters in horizontal and vertical forms in the encoding character set.
[0136] In this embodiment, the step of rendering the characters to be rendered according to the TTF glyph expression string may specifically be that the subtitle rendering module draws the TTF glyph expression string according to the drawText function of the third-party rendering tool skia, thereby rendering the characters to be rendered.
[0137] In this embodiment, when it is obtained that the typesetting mode of the character to be rendered is horizontal typesetting, the TTF glyph expression string of the character to be rendered is determined according to the TTF font file, and then the character expression string is drawn according to the drawText function to realize the rendering of the character to be rendered in horizontal typesetting. The process is simple and convenient.
[0138] Based on the above embodiments, a third embodiment of the subtitle rendering method of the present application is proposed.
[0139] See also Figure 4 As shown, Figure 4 : This is a flow chart of the third embodiment of the subtitle rendering method of the present application; in this embodiment, in step S203, if the typesetting mode of the character to be rendered is vertical typesetting, after the step of determining the support status of the character to be rendered for the vertical writing form, the subtitle rendering method may further include the following steps:
[0140] Step S206: If the character to be rendered does not support vertical writing, a TTF glyph expression string of the character to be rendered is obtained, and the character to be rendered is rendered according to the TTF glyph expression string.
[0141] In some examples, if the character to be rendered does not support vertical writing, the step of obtaining the TTF glyph expression string of the character to be rendered in step S206 may include the following steps:
[0142] First, if the character to be rendered does not support vertical writing, the encoding value of the character to be rendered is determined;
[0143] Then, according to the encoding value of the character to be rendered, a TTF glyph expression string of the vertical writing form of the character to be rendered is obtained from the TTF font file.
[0144] That is, in step S206 of the present embodiment, if the typeset mode of the character to be rendered is vertical typeset, but the character to be rendered does not support vertical writing, then the TTF glyph expression string of the character to be rendered is obtained. Specifically, this can be achieved by first determining the encoding value of the character to be rendered, and then obtaining the TTF glyph expression string of the vertical writing form of the character to be rendered from the TTF font file according to the encoding value of the character to be rendered.
[0145] It should be clear that the TTF font file in this embodiment pre-sets multiple TTF glyph expression strings that support characters in horizontal and vertical forms, as well as the encoding values of the characters that support characters in horizontal and vertical forms in the encoding character set.
[0146] In this embodiment, the step of rendering the characters to be rendered according to the TTF glyph expression string may specifically be that the subtitle rendering module draws the TTF glyph expression string according to the drawText function of the third-party rendering tool skia, thereby rendering the characters to be rendered.
[0147] In this embodiment, when it is obtained that the typesetting method of the character to be rendered is vertical typesetting, but the character to be rendered does not support vertical writing, the TTF glyph expression string of the character to be rendered is determined according to the TTF font file, and then the character expression string is drawn according to the drawText function to realize the rendering of the vertical typesetting character to be rendered. The process is simple and convenient.
[0148] Based on the above embodiments, a fourth embodiment of the subtitle rendering method of the present application is proposed.
[0149] This embodiment is described with a specific example, see Figure 5-1 to Figure 5-3 shown.
[0150] in, Figure 5-1 to Figure 5-3 The subtitle text information corresponding to the subtitle data to be rendered obtained in is all "HELLO".
[0151] and Figure 5-1 The typesetting information corresponding to the subtitle data to be rendered obtained in the example is "vertical typesetting", and only "H" in "HELLO" supports vertical writing; the specific implementation can adopt the steps in the first embodiment.
[0152] and Figure 5-2 The layout information corresponding to the subtitle data to be rendered obtained in the example is "horizontal layout"; the specific implementation may adopt the steps in the second embodiment.
[0153] and Figure 5-3 The typesetting information corresponding to the subtitle data to be rendered obtained in the example is "vertical typesetting", and no letter in "HELLO" supports vertical writing; the specific implementation can adopt the steps in the third embodiment.
[0154] Also, see Figure 6 As shown, based on the above-mentioned subtitle rendering method, the embodiment of the present application further proposes a subtitle rendering device, and the subtitle rendering device includes:
[0155] A first acquisition module 601 is used to acquire subtitle data to be rendered;
[0156] A determination module 602 is used to determine the layout of the characters to be rendered according to the subtitle data to be rendered;
[0157] The second acquisition module 603 is used to acquire a scalable vector graphic SVG glyph expression string of the vertical writing form of the character to be rendered if the typesetting mode of the character to be rendered is vertical typesetting and supports vertical form;
[0158] The rendering module 604 is used to render the character to be rendered according to the SVG character expression string.
[0159] The subtitle rendering device of the present application also includes other optional modules and adopts all the technical solutions of all the above embodiments, so it has at least all the beneficial effects brought by the technical solutions of the above embodiments, which will not be described one by one here.
[0160] In addition, an embodiment of the present application further proposes a computer-readable storage medium, on which a subtitle rendering program is stored. When the subtitle rendering program is executed by a processor, the steps of the subtitle rendering method described above are implemented.
[0161] The computer-readable storage medium includes volatile or non-volatile, removable or non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, computer program modules or other data). Computer-readable storage media include, but are not limited to, RAM (Random Access Memory), ROM (Read-Only Memory), EEPROM (Electrically Erasable Programmable read only memory), flash memory or other memory technology, CD-ROM (Compact Disc Read-Only Memory), digital versatile disk (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, disk storage, or any other medium that can be used to store the desired information and can be accessed by a computer.
[0162] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0163] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0164] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, disk, CD) as above, and includes a number of instructions for a terminal device to execute the methods of each embodiment of the present application.
[0165] The above are only optional embodiments of the present application, and do not limit the patent scope of the present application. All equivalent structural changes made by using the contents of the present application specification and drawings under the inventive concept of the present application, or directly / indirectly used in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A subtitle rendering method, characterized in that: The subtitle rendering method comprises the following steps: Get the subtitle data to be rendered; Determining the layout of the characters to be rendered according to the subtitle data to be rendered; If the typesetting mode of the character to be rendered is vertical typesetting, determining whether the character to be rendered supports vertical writing; If the character to be rendered supports vertical writing, obtaining a scalable vector graphic SVG glyph expression string of the vertical writing form of the character to be rendered, and rendering the character to be rendered according to the SVG glyph expression string; If the typesetting mode of the character to be rendered is vertical typesetting, the step of determining the support status of the character to be rendered for vertical writing comprises: If the typesetting mode of the character to be rendered is vertical typesetting, determining the encoding value of the character to be rendered; According to the encoding value of the word to be rendered, it is determined whether the word to be rendered is included in the SVG font file; wherein the SVG font file is pre-set with a plurality of SVG glyph expression strings of words supporting vertical writing, and encoding values of the words supporting vertical writing in a coded character set; If it is included, it is determined that the character to be rendered supports vertical writing; If not included, it is determined that the character to be rendered does not support vertical writing.
2. The subtitle rendering method according to claim 1, characterized in that: If the layout of the to-be-rendered characters is vertical layout, before the step of determining the encoding value of the to-be-rendered characters, the subtitle rendering method further includes: Determine the font type of the word to be rendered; According to the font type, the SVG font file corresponding to the font type is determined.
3. The subtitle rendering method according to claim 1, characterized in that: If the layout of the to-be-rendered characters is vertical layout, before the step of determining the encoding value of the to-be-rendered characters, the subtitle rendering method further includes: Convert TTF font files to SVG font intermediate files; Obtaining SVG glyph expression strings of all characters supporting vertical writing from the SVG font intermediate file; The SVG font file is generated according to the SVG glyph expression string of the character supporting vertical writing and the encoding value corresponding to the character supporting vertical writing in the encoding character set.
4. The subtitle rendering method according to any one of claims 1 to 3, characterized in that: The step of determining the layout of the characters to be rendered according to the subtitle data to be rendered comprises: Acquire subtitle text information and subtitle layout information from the subtitle data to be rendered; Determine the word to be rendered according to the subtitle text information; The typesetting mode of the characters to be rendered is determined according to the subtitle typesetting information.
5. The subtitle rendering method according to any one of claims 1 to 3, characterized in that: After the step of determining the layout of the characters to be rendered according to the subtitle data to be rendered, the subtitle rendering method further comprises the following steps: If the typesetting mode of the character to be rendered is horizontal typesetting, obtaining a TTF glyph expression string of the character to be rendered; Render the to-be-rendered character according to the TTF character expression string.
6. The subtitle rendering method according to any one of claims 1 to 3, characterized in that: If the typesetting mode of the to-be-rendered characters is vertical typesetting, after the step of determining the support status of the to-be-rendered characters for vertical writing, the subtitle rendering method further comprises the following steps: If the character to be rendered does not support vertical writing, obtaining a TTF glyph expression string of the character to be rendered; Render the to-be-rendered character according to the TTF character expression string.
7. The subtitle rendering method according to claim 5, characterized in that: If the typesetting mode of the character to be rendered is horizontal typesetting, the step of obtaining the TTF glyph expression string of the character to be rendered includes: If the typesetting mode of the character to be rendered is horizontal typesetting, determining the encoding value of the character to be rendered; According to the encoding value of the character to be rendered, a TTF glyph expression string in horizontal form of the character to be rendered is obtained from a TTF font file; wherein the TTF font file presets a plurality of TTF glyph expression strings of characters supporting horizontal form and vertical form, and the encoding values of the characters supporting horizontal form and vertical form in a coded character set.
8. The subtitle rendering method according to claim 6, characterized in that: If the character to be rendered does not support vertical writing, the step of obtaining a TTF glyph expression string of the character to be rendered includes: If the character to be rendered does not support vertical writing, determining the encoding value of the character to be rendered; According to the encoding value of the character to be rendered, a TTF glyph expression string of the vertical writing form of the character to be rendered is obtained from the TTF font file; wherein the TTF font file presets a plurality of TTF glyph expression strings of characters supporting horizontal form and vertical form, and the encoding values of the characters supporting horizontal form and vertical form in the encoding character set.
9. A subtitle rendering device, characterized in that: The subtitle rendering device comprises: A first acquisition module, used to acquire subtitle data to be rendered; A determination module, used for determining the layout mode of the characters to be rendered according to the subtitle data to be rendered; A second acquisition module is used for acquiring a scalable vector graphic SVG glyph expression string of the vertical writing form of the character to be rendered if the typesetting mode of the character to be rendered is vertical typesetting and supports vertical writing; A rendering module, used for rendering the to-be-rendered character according to the SVG character expression string; The second acquisition module is further used to determine the encoding value of the character to be rendered if the typeset mode of the character to be rendered is vertical typeset; judge whether the character to be rendered is included in the SVG font file according to the encoding value of the character to be rendered; if included, determine that the character to be rendered supports vertical writing; if not included, determine that the character to be rendered does not support vertical writing; wherein, the SVG font file is pre-set with a plurality of SVG glyph expression strings of characters supporting vertical writing, and the encoding values of the characters supporting vertical writing in the encoding character set.
10. A subtitle rendering device, characterized in that: The subtitle rendering device comprises: a memory, a processor, and a subtitle rendering program stored in the memory and running on the processor, wherein the subtitle rendering program implements the steps of the subtitle rendering method according to any one of claims 1 to 8 when executed by the processor.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a subtitle rendering program, and when the subtitle rendering program is executed by a processor, the steps of the subtitle rendering method according to any one of claims 1 to 8 are implemented.
