(5)UpdateCharRec

该函数的源码分析如下:

procedure TTextLayoutNG.UpdateCharRec(const ACanvas: TCanvas; NeedBitmap: Boolean; var NewRec: PCharRec;
HasItem: Boolean; const CharDic: TCharDic; const AFont: TFont; const Ch: UCS4Char; const NeedPath: Boolean = False);
var
Map: TBitmapData;
J: Integer;
Bitmap: TBitmap;
LFont: TFont;
GlyphSettings: TFontGlyphSettings;
begin
{
新建一个记录,或释放原记录中的图形对象
}
if not HasItem then
New(NewRec)
else
begin
FreeAndNil(NewRec.Glyph);
FreeAndNil(NewRec.Bitmap);
end; {
如果指定了字体则使用之,否则使用缺省字体
}
if not Assigned(AFont) then
LFont := Self.Font
else
LFont := AFont; {
使用Bitmap形式存储,或使用Path存储渲染过程
}
GlyphSettings := [];
if NeedBitmap then
GlyphSettings := [TFontGlyphSetting.Bitmap, TFontGlyphSetting.PremultipliedAlpha];
if NeedPath then
GlyphSettings := GlyphSettings + [TFontGlyphSetting.Path]; {
在TFontGlyphManager中使用当前的FontGlyph生成缺省图形
}
NewRec.Glyph := TFontGlyphManager.Current.GetGlyph(Ch, LFont, FScale, GlyphSettings);
{
计算基准线的位置
}
CharDic.Baseline := TFontGlyphManager.Current.GetBaseline(LFont, FScale); {
如果采用图形模式,则生成之
}
if not (TFontGlyphStyle.NoGlyph in NewRec.Glyph.Style) and Assigned(NewRec.Glyph.Bitmap) and (NewRec.Glyph.Bitmap.Width > ) and (NewRec.Glyph.Bitmap.Height > ) then
begin
{
采用图形渲染模式,生成Bitmap
}
if FRendering > then
begin
Bitmap := TBitmap.Create(NewRec.Glyph.Bitmap.Width + AntiAliasMargin * , NewRec.Glyph.Bitmap.Height + AntiAliasMargin * );
Bitmap.BitmapScale := FScale;
{
将Glyph中的图形复制到Bitmap中
}
if Bitmap.Map(TMapAccess.Write, Map) then
try
        FillChar(Map.Data^, Map.Pitch * Map.Height, );
NewRec.Bitmap := Bitmap;
NewRec.SrcRect := RectF(, , NewRec.Glyph.Bitmap.Width, NewRec.Glyph.Bitmap.Height);
NewRec.SrcRect.Offset(AntiAliasMargin, AntiAliasMargin);
for J := to NewRec.Glyph.Bitmap.Height - do
Move(NewRec.Glyph.Bitmap.Scanline[J]^, Map.GetPixelAddr(AntiAliasMargin, J + AntiAliasMargin)^, NewRec.Glyph.Bitmap.Pitch);
finally
Bitmap.Unmap(Map);
end;
{
构建图形列表,并将其放入
}
if not Assigned(FNewGlyphList) then
FNewGlyphList := TList<PCharRec>.Create;
FNewGlyphList.Add(NewRec);
end
else
{
直接将Glyph映射到Bitmap中
}
MapGlyphToCache(NewRec);
end
else
{
采用Path模式
}
begin
NewRec.Bitmap := nil;
NewRec.SrcRect := RectF(, , , );
end; {
加入到列表中
}
if not HasItem then
CharDic.Add(Ch, NewRec);
end;

其中2个重要的函数是:

TFontGlyphManager.Current.GetGlyph

TFontGlyphManager.Current.GetBaseline

FireMonkey 源码学习(5)的更多相关文章

  1. FireMonkey 源码学习(1)

    FireMonkey采用了与VCL不同的机制,很多基础类已经重新编写了,好在一如既往地提供了源代码,故此有机会学习一下. 一.图形引擎 FireMonkey采用了纯图形化技术解决可视化控件,而不是使用 ...

  2. FireMonkey 源码学习(3)

    五.TTextLayoutNG 在FMX.TextLayout.GPU.pas文件中,实现了几个基础功能,其中: (1)渲染单元 在TextLayout中,每一批同字体和颜色的1~n个字符,组成一个最 ...

  3. FireMonkey 源码学习(2)

    三.TControl FireMonkey重写了TControl的代码,实现了众多接口,如下图: 基类上实现了众多功能,这里不详细描述. 四.TEdit 编辑框是从TControl—TStyledCo ...

  4. FireMonkey 源码学习(6)

    (6)GetGlyph和GetBaseline TFontGlyphManager是一个抽象类,在不同平台上的实现是不同的,以Windows为例,在FMX.FontGlyphs.Win.pas文件中定 ...

  5. FireMonkey 源码学习(4)

    (4)DoDrawLayout DoDrawLayout函数的源代码分析如下: procedure TTextLayoutNG.DoDrawLayout(const ACanvas: TCanvas) ...

  6. Java集合专题总结(1):HashMap 和 HashTable 源码学习和面试总结

    2017年的秋招彻底结束了,感觉Java上面的最常见的集合相关的问题就是hash--系列和一些常用并发集合和队列,堆等结合算法一起考察,不完全统计,本人经历:先后百度.唯品会.58同城.新浪微博.趣分 ...

  7. jQuery源码学习感想

    还记得去年(2015)九月份的时候,作为一个大四的学生去参加美团霸面,结果被美团技术总监教育了一番,那次问了我很多jQuery源码的知识点,以前虽然喜欢研究框架,但水平还不足够来研究jQuery源码, ...

  8. MVC系列——MVC源码学习:打造自己的MVC框架(四:了解神奇的视图引擎)

    前言:通过之前的三篇介绍,我们基本上完成了从请求发出到路由匹配.再到控制器的激活,再到Action的执行这些个过程.今天还是趁热打铁,将我们的View也来完善下,也让整个系列相对完整,博主不希望烂尾. ...

  9. MVC系列——MVC源码学习:打造自己的MVC框架(三:自定义路由规则)

    前言:上篇介绍了下自己的MVC框架前两个版本,经过两天的整理,版本三基本已经完成,今天还是发出来供大家参考和学习.虽然微软的Routing功能已经非常强大,完全没有必要再“重复造轮子”了,但博主还是觉 ...

随机推荐

  1. python爬虫-基础入门-爬取整个网站《1》

    python爬虫-基础入门-爬取整个网站<1> 描述: 使用环境:python2.7.15 ,开发工具:pycharm,现爬取一个网站页面(http://www.baidu.com)所有数 ...

  2. caffe-ssd的GPU安装时make runtest报错: BatchReindexLayerTest/3.TestGradient, where TypeParam = caffe::GPUDevice<double>

    报错原因:装了两个cuda,BatchReindexLayerTest/3.TestGradient不能确定用那个 解决办法1:删除其中一个(最好删除9.1,TensorFlow支持的是9.0,为了后 ...

  3. vs2015 C#打包程序为exe

    说明:将自己写的C#源代码打包后生成exe,直接安装在别人的电脑上运行,就像我们在网上下载别人的软件一样,很高大上,vs2015提供了打包和生成exe功能: 步骤一.打开vs2015(其他版本应该也是 ...

  4. numpy数学数据处理

    数学和统计方法 sum 对数组中全部或某轴向的元素求和.零长度的数组的sum为0. mean 算术平均数.零长度的数组的mean为NaN. import numpy as np import nump ...

  5. MQ的使用场景

    一.消息队列概述消息队列中间件是分布式系统中重要的组件,主要解决应用解耦,异步消息,流量削锋等问题,实现高性能,高可用,可伸缩和最终一致性架构.目前使用较多的消息队列有ActiveMQ,RabbitM ...

  6. 【转】阿里出品的ETL工具dataX初体验

    原文链接:https://www.imooc.com/article/15640 来源:慕课网 我的毕设选择了大数据方向的题目.大数据的第一步就是要拿到足够的数据源.现实情况中我们需要的数据源分布在不 ...

  7. Codeforce 834A - The Useless Toy

    Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kin ...

  8. P1216 数字金字塔

    P1216  数字金字塔 我们可以用 f [ i ] [ j ] 表示从(1,1)出发,到达(i,j)的最大权值和. (i , j)可以由(i - 1 , j)或者(i - 1 , j - 1)转化来 ...

  9. python-数据分析与展示(Numpy、matplotlib、pandas)---2

    笔记内容整理自mooc上北京理工大学嵩天老师python系列课程数据分析与展示,本人小白一枚,如有不对,多加指正 1.python自带的图像库PIL 1.1常用API  Image.open()    ...

  10. Java用Gson遍历json所有节点

    <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</ar ...