CN104298504A - Method for achieving font rendering based on FreeType font engine - Google Patents

Method for achieving font rendering based on FreeType font engine Download PDF

Info

Publication number
CN104298504A
CN104298504A CN201410485483.9A CN201410485483A CN104298504A CN 104298504 A CN104298504 A CN 104298504A CN 201410485483 A CN201410485483 A CN 201410485483A CN 104298504 A CN104298504 A CN 104298504A
Authority
CN
China
Prior art keywords
font
freetype
size
bitmap
engine
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201410485483.9A
Other languages
Chinese (zh)
Inventor
张翼
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Of Ancient India Day Infotech Share Co Ltd In Wuxi
Original Assignee
Of Ancient India Day Infotech Share Co Ltd In Wuxi
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Of Ancient India Day Infotech Share Co Ltd In Wuxi filed Critical Of Ancient India Day Infotech Share Co Ltd In Wuxi
Priority to CN201410485483.9A priority Critical patent/CN104298504A/en
Publication of CN104298504A publication Critical patent/CN104298504A/en
Pending legal-status Critical Current

Links

Landscapes

  • Controls And Circuits For Display Device (AREA)

Abstract

The invention discloses a method for achieving font rendering based on a FreeType font engine. The method comprises the steps that a FreeType engine library is initialized, and a freetype.lib font library is loaded; the FT_Face handle of a font is established, an object of the freetype.lib font library is read, and the read object is processed and transformed into a bitmap; the bitmap is rendered into a texture cache, and then is written into a chartlet. The font is rendered onto a texture through the FreeType, and then is displayed through the texture chartlet. The purpose of displaying Chinese characters quickly and conveniently is achieved.

Description

Based on the method realizing font drafting of FreeType font engine
Technical field
The present invention relates to field of information processing, particularly, relate to and a kind ofly realize the method that font draws, by character rendering to texture and the method shown based on FreeType font engine.
Background technology
At present, in software development, usually the display considering font is not needed, it has the function based on operating system to provide, but the development of computer system, efficiently, fast, font attractive in appearance has become a demand in market, especially closely bound up with the life of people in electronic apparatus application, at home in online game, Chinese character covers a lot of game language used, but in scene of game, video card does not but support Chinese character, need for font is resolved, and most of engine all provides the interface of Font processing.
Use diverse ways to realize the display of font in a lot of game, but ununified regulation, but these effects of drawing the method display of font are imperfect, the defects such as sight equation.
Summary of the invention
The object of the invention is to, for the problems referred to above, propose a kind of method realizing font drafting based on FreeType font engine, quick and easy by chinese disply advantage out to realize.
For achieving the above object, the technical solution used in the present invention is:
Based on the method realizing font drafting of FreeType font engine, comprising:
Initialization FreeType engine storehouse, loads the step of freetype.lib fontlib;
Create the FT_Face handle of font, read the object of above-mentioned freetype.lib fontlib, and the object of reading is carried out process the step being converted into bitmap;
And
In above-mentioned bitmap render to texture buffer memory, then write the step in pinup picture.
Preferably, the FT_Face handle of described establishment font, reads the object of above-mentioned freetype.lib fontlib, and is carried out by the object of reading processing in the step being converted into bitmap and specifically comprise,
The step of the font size FT_Size set font;
And
Create each font FT_GyphSlot of font, and font is converted into the step of bitmap.
Preferably, the step of the above-mentioned font size FT_Size set font is specially:
In the handle object created, each handle object has the class FT_Size object of one or more size that sets font, and sized objects is used for depositing width and the altitude information of designated character, the corresponding size of appearance object of each new establishment.
Preferably, each font FT_GyphSlot of described establishment font, and the step that font typeface is converted into bitmap is specifically comprised:
Create the step of the Glyph of font itself;
Create the step of the frame Glyph of font.
Preferably, described font size FT_Size is set to No. 12 fonts.
Technical scheme of the present invention has following beneficial effect:
Technical scheme of the present invention, realizes the method for font drafting based on FreeType font engine.FreeType is a font engine of increasing income, it supports playing up of monochrome bitmap, anti-aliasing bitmap, and provide unified interface to visit multiple font formatted file, comprise TrueType, OpenType, CFF, CID, window FONT/FNT/ etc., FreeType, on font render to texture, is then shown by texture mapping.Reach quick and easy by chinese disply object out.
Below by drawings and Examples, technical scheme of the present invention is described in further detail.
Accompanying drawing explanation
Fig. 1 is the method flow diagram realizing font drafting based on FreeType font engine described in the embodiment of the present invention;
Fig. 2 is the common pinup picture schematic diagram of the font generated;
Fig. 3 be generate font retouch limit pinup picture schematic diagram;
Fig. 4 is the font groove schematic diagram that the common pinup picture of the font generated shown in Fig. 2 is corresponding;
The font that Fig. 5 is the generation shown in Fig. 3 retouch font groove schematic diagram corresponding to limit pinup picture;
Fig. 6 is the tolerance schematic diagram of horizontal layout.
Embodiment
Below in conjunction with accompanying drawing, the preferred embodiments of the present invention are described, should be appreciated that preferred embodiment described herein is only for instruction and explanation of the present invention, is not intended to limit the present invention.
As shown in Figure 1, a kind of method realizing font drafting based on FreeType font engine, comprising:
Initialization FreeType engine storehouse, loads the step of freetype.lib fontlib;
Create the FT_Face handle of font, read the object of freetype.lib fontlib, and the object of reading is carried out process the step being converted into bitmap;
And
In bitmap render to texture buffer memory, then write the step in pinup picture.
Preferably, create the FT_Face handle of font, read the object of freetype.lib fontlib, and the object of reading is carried out process in the step being converted into bitmap and specifically comprise,
The step of the font size FT_Size set font;
And
Create each font FT_GyphSlot of font, and font is converted into the step of bitmap.
Preferably, the step of the font size FT_Size set font is specially:
In the handle object created, each handle object has the class FT_Size object of one or more size that sets font, and sized objects is used for depositing width and the altitude information of designated character, the corresponding size of appearance object of each new establishment.
Preferably, create each font FT_GyphSlot of font, and the step that font typeface is converted into bitmap specifically comprised:
Create the step of the Glyph of font itself;
Create the step of the frame Glyph of font.
Below in conjunction with program, embodiment is described:
Freetype is the function library of an operation font, not only raster font can be processed, also can process multiple vector fonts, for upper level applications provides a unified calling interface, technical solution of the present invention is that the interface that have invoked in FreeType storehouse realizes.Concrete steps are as follows:
First: initialization FreeType engine storehouse, load freetype.lib fontlib;
In program design, stated by following:
FT_Library ftlibrary; Create the example in storehouse
FT_Init_FreeType (& ftlibrary) // create new storehouse object, the pattern of this establishment wants simple and convenient point, and module list can calculate dynamically when building.
When creating storehouse object, all FT are the fathers of other objects, such as: FT_FACE, FT_module are its subobjects.When destroying these subobjects, parent object is just meaningless.Before doing any operation, all to create a new storehouse example, in the example in this storehouse, comprise memory management object, list object, preservation appearance object belong to that font drives, storehouse example.
Second: the FT_Face handle creating font;
In program design, handle is a kind of special intelligent pointer, just needs handle when the memory block that the system will quoting other in an application program manages or object.So create the outward appearance that font handle is exactly a font, an appearance object FT_New_Memory_Fac() create, it describes the attribute of global word volume data usually.Directly can be accessed by program, because the present invention is the realization to font based on FreeTYpe engine, so need to introduce the object in font engine.Font FT_Face handle can be created: FT_New_Memory_Face (_ ftLibrary, _ fontBuffer, (FT_Long) fontBufferSize, faceIndex, & result) by following code,
Parameter meaning is wherein: _ ftLibrary character library handle, the buffer memory buffer of the font file that _ fontBuffer reads, the buffer size of the font file that fontBufferSize reads, faceIndex is defaulted as 0, get the first character shape (some font file may be with multiple font) in font file exactly, whether result returns and loads successfully.
This function of FT_New_Memory_Face () can be used for the data creation that directly reads from internal memory or open a FT_FACE object.
A) the font size FT_Size set font;
The handle object created, each handle object has the class FT_Size object of one or more size that sets font, sized objects is used for depositing width and the altitude information of designated character, the corresponding size of appearance object of each new establishment, and the font size function that it sets font is:
FT_Set_Char_Size(result, ftSize, 0, mResolution, mResolution)
Wherein whether result returns and loads successfully, the size of ftSize font size, and we are set to No. 12 fonts usually, mResolution, mResolution resolution parameter, adopts default value to be respectively 72,72.
B) create each font FT_GyphSlot of font, and the font of font is converted into bitmap;
The reflection of character is called font, and according to writing, usage and context, when individual character can have multiple different reflection, that is: multiple font, single character also can by a font.
When the size of the setting of a loading font, between font, typesetting is also very important, and in order to typesetting is more attractive in appearance, technical solution of the present invention quotes horizontal typesetting font in font engine to tell about the horizontal typesetting format of font:
As shown in Figure 6: the arrow of horizontal direction represents baseline, can make level or vertical.In order to rendering text, baseline has a virtual point arrived initial point, it is used for locating font.
Wherein Width is the width of the frame of glyph image, Height is the frame height of glyph image, bearingX is the horizontal range on leftmost border from present cursor position to glyph image, bearingY is the vertical range from baseline to coboundary frame, Advance is step width, when font is drawn as the part of character string, be used for increasing the horizontal range of a position.
Measured by font and describe this distance and carry out typesetting text, a usual font has two set of metrics: be used for the horizontal text alignment of typesetting font be used for the font of the vertical text alignment of typesetting, but only have little font format to provide vertical tolerance, the tolerance of such font can convenient search, more manageable glyph image.
Each FT_Face object comprises one group of font, and these fonts can exist in font file in random order.And in font file, comprise one or more table, be called character list (Charmap).
When a dynamic creation FT_Face object, usually with the mapping table of a font, character code is used for be mapped to corresponding glyph slot(font groove) index value, this font groove provides the place that is deposited font, the reflection of font can be loaded one by one, once after font groove creates, any font reflection can load wherein and without the need to other Memory Allocation, needs to overlap pinup pictures preserve for the Glyph of font and the frame Glyph of font itself creates 2 simultaneously.
B1) Glyph of font itself, is created;
First a font Glyph is loaded,
FT_Load_Char(mFace, _id, FT_LOAD_DEFAULT) != 0
Wherein mFace is font handle FT_Face, _ id is that a font transforms the font coded format of coming
Next plays up this font glyph
FT_Render_Glyph(mFace->glyph, mMono FT_RENDER_MODE_MONO : FT_RENDER_MODE_NORMAL)
Wherein Mono pattern (raster font), and judge which type of uses play up mode:
Whether play up or the data render of 256 gray scale image strip Alpha passages with the generation of freetype font with raster font.
B2) the frame Glyph of font, is created;
The establishment of frame and the similar of above-mentioned normal font Glyph, some difference of the API of the freetype just called:
Its implementation procedure is as follows:
FT_Get_Glyph (mFace->glyph, & glyph); // obtain before create font
FT_Stroker_New(FontManager::getInstance().getFTLibrary(), &stroker);
FT_Stroker_Set(stroker, mStrokeSize * 64, FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0);FT_RENDER_MODE_MONO : FT_RENDER_MODE_NORMAL, 0, 0);
FT_Glyph_Stroke(&glyph, stroker, 0);
FT_Stroker_Done(stroker);
FT_Glyph_To_Bitmap(&glyph, mMono FT_RENDER_MODE_MONO : FT_RENDER_MODE_NORMAL, 0, 0);
FT_Bitmap &bitmap = ((FT_BitmapGlyph)glyph)->bitmap;
The above-mentioned buffer being the api utilizing freetype to carry and generating frame information.
3rd: in the frame render to texture buffer memory of the glyph of font itself and font, then write in pinup picture;
Obtain the image information be kept in freetype: implementation procedure is as follows:
FT_Bitmap &bitmap = slot->bitmap;
And these information are write in pinup picture, record the corresponding information of this font Glyph and comprise this and put up UV on figure, the width of font, the height of font, the lateral excursion of font, the vertical misalignment of font.Specifically as shown in Figures 2 to 5.
English in the technical program claim to be in programming conventional term, and it is known to be that it is meant to for those skilled in the art.
Last it is noted that the foregoing is only the preferred embodiments of the present invention, be not limited to the present invention, although with reference to previous embodiment to invention has been detailed description, for a person skilled in the art, it still can be modified to the technical scheme described in foregoing embodiments, or carries out equivalent replacement to wherein portion of techniques feature.Within the spirit and principles in the present invention all, any amendment done, equivalent replacement, improvement etc., all should be included within protection scope of the present invention.

Claims (5)

1., based on the method realizing font drafting of FreeType font engine, it is characterized in that, comprising:
Initialization FreeType engine storehouse, loads the step of freetype.lib fontlib;
Create the FT_Face handle of font, read the object of above-mentioned freetype.lib fontlib, and the object of reading is carried out process the step being converted into bitmap;
And
In above-mentioned bitmap render to texture buffer memory, then write the step in pinup picture.
2. the method realizing font drafting based on FreeType font engine according to claim 1, it is characterized in that, the FT_Face handle of described establishment font, read the object of above-mentioned freetype.lib fontlib, and the object of reading is carried out process in the step being converted into bitmap and specifically comprise
The step of the font size FT_Size set font;
And
Create each font FT_GyphSlot of font, and font typeface is converted into the step of bitmap.
3. the method realizing font drafting based on FreeType font engine according to claim 2, it is characterized in that, the step of the above-mentioned font size FT_Size set font is specially:
In the handle object created, each handle object has the class FT_Size object of one or more size that sets font, and sized objects is used for depositing width and the altitude information of designated character, the corresponding size of appearance object of each new establishment.
4. according to claim 2ly realize based on FreeType font engine the method that font draws, it is characterized in that, each font FT_GyphSlot of described establishment font, and the step that font typeface is converted into bitmap is specifically comprised:
Create the step of the Glyph of font itself;
Create the step of the frame Glyph of font.
5., according to the arbitrary described method realizing font drafting based on FreeType font engine of claim 2 to 4, it is characterized in that, described font size FT_Size is set to No. 12 fonts.
CN201410485483.9A 2014-09-22 2014-09-22 Method for achieving font rendering based on FreeType font engine Pending CN104298504A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410485483.9A CN104298504A (en) 2014-09-22 2014-09-22 Method for achieving font rendering based on FreeType font engine

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410485483.9A CN104298504A (en) 2014-09-22 2014-09-22 Method for achieving font rendering based on FreeType font engine

Publications (1)

Publication Number Publication Date
CN104298504A true CN104298504A (en) 2015-01-21

Family

ID=52318247

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410485483.9A Pending CN104298504A (en) 2014-09-22 2014-09-22 Method for achieving font rendering based on FreeType font engine

Country Status (1)

Country Link
CN (1) CN104298504A (en)

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105513108A (en) * 2015-12-11 2016-04-20 中国航空工业集团公司西安航空计算技术研究所 Word stock drawing method based on texture mapping
CN105654541A (en) * 2015-12-31 2016-06-08 网易(杭州)网络有限公司 Window image processing method and device
CN106384373A (en) * 2016-08-31 2017-02-08 广州博冠信息科技有限公司 Character display method and device
CN106683189A (en) * 2016-11-29 2017-05-17 浙江科澜信息技术有限公司 Method of rendering text in three-dimensional scene
CN107221020A (en) * 2017-05-27 2017-09-29 北京奇艺世纪科技有限公司 A kind of word texture rendering method and device
CN108986193A (en) * 2018-07-10 2018-12-11 武汉国遥新天地信息技术有限公司 It is a kind of three-dimensional text retouch side method for drafting
CN111105474A (en) * 2019-12-19 2020-05-05 广州酷狗计算机科技有限公司 Font drawing method and device, computer equipment and computer readable storage medium
CN112652046A (en) * 2020-12-18 2021-04-13 完美世界(重庆)互动科技有限公司 Game picture generation method, device, equipment and storage medium
US11928419B2 (en) 2020-09-21 2024-03-12 Boe Technology Group Co., Ltd. Information display method and apparatus, and storage medium and electronic device

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101008939A (en) * 2007-01-25 2007-08-01 深圳创维-Rgb电子有限公司 Implementation method of dot matrix word library of embedded system

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101008939A (en) * 2007-01-25 2007-08-01 深圳创维-Rgb电子有限公司 Implementation method of dot matrix word library of embedded system

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
黄秀珍,何加铭,邰晓英: "《基于freetype嵌入式矢量字体引擎的研究》", <宁波大学学报> *

Cited By (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105513108A (en) * 2015-12-11 2016-04-20 中国航空工业集团公司西安航空计算技术研究所 Word stock drawing method based on texture mapping
CN105654541A (en) * 2015-12-31 2016-06-08 网易(杭州)网络有限公司 Window image processing method and device
CN105654541B (en) * 2015-12-31 2018-09-14 网易(杭州)网络有限公司 Video in window treating method and apparatus
CN106384373A (en) * 2016-08-31 2017-02-08 广州博冠信息科技有限公司 Character display method and device
CN106384373B (en) * 2016-08-31 2019-06-21 广州博冠信息科技有限公司 A kind of character displaying method and device
CN106683189B (en) * 2016-11-29 2019-09-27 浙江科澜信息技术有限公司 A method of the rendering type in three-dimensional scenic
CN106683189A (en) * 2016-11-29 2017-05-17 浙江科澜信息技术有限公司 Method of rendering text in three-dimensional scene
CN107221020A (en) * 2017-05-27 2017-09-29 北京奇艺世纪科技有限公司 A kind of word texture rendering method and device
CN108986193A (en) * 2018-07-10 2018-12-11 武汉国遥新天地信息技术有限公司 It is a kind of three-dimensional text retouch side method for drafting
CN111105474A (en) * 2019-12-19 2020-05-05 广州酷狗计算机科技有限公司 Font drawing method and device, computer equipment and computer readable storage medium
US11928419B2 (en) 2020-09-21 2024-03-12 Boe Technology Group Co., Ltd. Information display method and apparatus, and storage medium and electronic device
CN112652046A (en) * 2020-12-18 2021-04-13 完美世界(重庆)互动科技有限公司 Game picture generation method, device, equipment and storage medium
CN112652046B (en) * 2020-12-18 2024-03-22 完美世界(重庆)互动科技有限公司 Game picture generation method, device, equipment and storage medium

Similar Documents

Publication Publication Date Title
CN104298504A (en) Method for achieving font rendering based on FreeType font engine
EP4198909A1 (en) Image rendering method and apparatus, and computer device and storage medium
US10789770B1 (en) Displaying rich text on 3D models
KR102523843B1 (en) Font rendering method, device and computer readable storage medium
US8959431B2 (en) Low resolution placeholder content for document navigation
KR20150091132A (en) Page rendering method and apparatus
CN101699426A (en) Document format conversion system and method
CN111221596B (en) Font rendering method, apparatus and computer readable storage medium
CN109636885B (en) Sequential frame animation production method and system for H5 page
CN107707965B (en) Bullet screen generation method and device
US10311060B2 (en) Glyph management in texture atlases
CN108961361B (en) Method and system for generating special effect text image and computer equipment
US11367231B2 (en) System for generating snapping guides for a multi-path glyph
CN101593171B (en) Font file capable of being accessed by memory mapping and access method thereof
CN111324381B (en) Development system, development method, development apparatus, computer device, and storage medium
CN108986193A (en) It is a kind of three-dimensional text retouch side method for drafting
US8818092B1 (en) Multi-threaded text rendering
CN114049424A (en) Efficient character drawing and displaying method based on three-dimensional rendering engine
CN111399788B (en) Media file playing method and media file playing device
CN114625990A (en) Method, device, equipment and medium for rendering webpage end grid data
CN100405293C (en) Dot matrix graphic interface development method
CN110647352B (en) Data migration method, terminal and storage medium
CN116341490A (en) Method for realizing variable fonts in automobile instrument HMI based on FreeType
US20180189251A1 (en) Automatic multi-lingual editing method for cartoon content
CA2969778A1 (en) Glyph management in texture atlases

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20150121

RJ01 Rejection of invention patent application after publication