TCAX 字幕特效制作工具官方论坛 | ASS | TCAS | Python | Aegisub | Lua

 找回密码
 新人加入
查看: 5751|回复: 1

GDIfont模块使用方法 [复制链接]

Moderator

youkaze

Rank: 5Rank: 5

发表于 2012-4-28 12:50:04 |显示全部楼层
本帖最后由 四月一日 君寻 于 2012-8-5 20:26 编辑

第一次写这种使用方法 写的不好请轻轻的喷哈……

感谢牛奶大 辛苦了 终于把这个坑给填了

首先来说一下GDIfont模块是用来干嘛的吧 就素弥补  普通像素字  对  普通ASS文字  的定位偏差的。本文档用  GDI像素字代码  当做范例,mask 在完整工程中会有提供所以不做讲解。

1.像素字py脚本的设置(GDI像素字代码与freetype的比较)见以下代码:
  1. from tcaxPy import *
  2. from gdiFont import *  #加入GDIfont模块

  3. def tcaxPy_Init():
  4.     global _Fs
  5.     #global _Font
  6.    
  7.     global GdiFont   #GDIfont
  8.    
  9.     _Fs = GetVal(val_FontSize)  
  10.     fontFileName = GetVal(val_FontFileName)  
  11.     faceID = GetVal(val_FaceID)            
  12.     spacing = GetVal(val_Spacing)      
  13.     spaceScale = GetVal(val_SpaceScale)
  14.     color = MakeRGB(255, 255, 255)
  15.     bord = 0         
  16.     isOutline = False     

  17.     #_Font = InitFont(fontFileName, faceID, _Fs, spacing, spaceScale, color, bord, isOutline)
  18.    
  19.     GdiFont = gfInitFont(GetVal(val_FontFaceName), _Fs, GetVal(val_Spacing), GetVal(val_SpaceScale), 0, False)   #GDIfont

  20. def tcaxPy_Fin():
  21.     #FinFont(_Font)
  22.      
  23.     gfFinFont(GdiFont)   #GDIfont

  24. def tcaxPy_Main(_i, _j, _n, _start, _end, _elapk, _k, _x, _y, _a, _txt):
  25.     ASS_BUF  = []     
  26.     TCAS_BUF = []
  27.     ass_main(ASS_BUF, SubL(_start, _end, 0,), pos(_x, _y) + color1('0000FF')+bord(0)+shad(0), _txt)
  28.    
  29.     points = gfGetPoints(GdiFont, _txt)  #GDIfont

  30.     PIX = PixFromPoints(points)   #GDIfont
  31.    
  32.     #PIX = TextPix(_Font, _txt)
  33.     initPosX = _x - int(_a / 2 + 0.5) + PIX[0][0]   
  34.     initPosY = _y - int(_Fs / 2 + 0.5) + PIX[0][1]     
  35.     for h in range(PIX[1][1]):                        
  36.         posY = initPosY + h                     
  37.         for w in range(PIX[1][0]):                  
  38.             posX = initPosX + w                     
  39.             idx  = 4 * (h * PIX[1][0] + w)         
  40.             pixR = PIX[2][idx + 0]                 
  41.             pixG = PIX[2][idx + 1]            
  42.             pixB = PIX[2][idx + 2]            
  43.             pixA = PIX[2][idx + 3]            
  44.             if pixA != 0:            
  45.                 ass_main(ASS_BUF, SubL(_start, _end, 0, Pix_Style), pos(posX, posY) + color1('FF5E00') + alpha1(255 - pixA), PixPt())
  46.     return (ASS_BUF, TCAS_BUF)
复制代码

注:以上代码中用 “#” 注释掉的部分是原freetype字体引擎生成的 像素字 ,可以对比一下添加了哪些GDIfont的代码(由于默认像素字颜色是黑色所以ass_main中颜色得自己改以下)

2.关于tcc文件的设置:
使用GDIfont需注意TCC文件中 字体大小(font size)以及字间距(spacing)的设置
font size:推荐用偶数(如果要用字大小31,41这种情况的话建议都改为30, 40或32, 42)
spacing :推荐设置为0 (要对字间距做修改推荐设置成偶数, 2, 4, 6...). 并且在计算dx的时候用(_a + _spacing) / 2 代替 原来的_a, 其中_spacing = GetVal(val_Spacing), 此修正公式可参考 http://www.tcax.org/forum.php?mod=viewthread&tid=177

mask的tcc文件设置同上

见以下tcc文件:
  1. # tcc file version

  2. < tcc file version = 1.0 >


  3. # mode configuration

  4. < inherit ass header = false >
  5. < k mode = syl >
  6. < text layout = horizontal >
  7. < tcaxpy init = true >
  8. < tcaxpy user = false >
  9. < tcaxpy fin = true >


  10. # py settings

  11. < py file = ceshiGDIfontlizi.py >    < beg line = 1 >    < end line = 0 >


  12. # main settings

  13. < k-timed ass file = ceshi_k.ass >
  14. < font file = epkgobld_1.ttf >    < font face id = 1 >    < font size = 46 >
  15. < fx width = 1280 >    < fx height = 720 >    < fx fps = 23.976 >
  16. < alignment = 2 >
  17. < x offset = 10 >    < y offset = 10 >
  18. < spacing = 0 >    < space scale = 0.5 >


  19. # style settings

  20. < font face name = "" >
  21. < bord = 2 >    < shad = 0 >
  22. < primary color = 9393FF >    < secondary color = FFFFFF >    < outline color = FFFFFF >    < back color = FFFFFF >
  23. < primary alpha = 0 >    < secondary alpha = 255 >    < outline alpha = 0 >    < back alpha = 255 >


  24. # additional settings

  25. < blur = 0.0 >
复制代码

3.以下是 freetype,GDI,tcc设置不同的对比图:

1:freetype字体引擎生成的像素字与ASS普通字:
freetype.jpg
蓝色为像素字 红色为普通ASS字。

2:GDI字体引擎生成的像素字语ASS普通字:
GDI.jpg
蓝色为像素字 红色为普通ASS字。

3:使用GDIfont模块tcc文件的设置不同:
1_45.jpg
TCC中 font size = 45   spacing = 1 蓝色为像素字 红色为普通ASS字。


GDI.jpg
TCC中 font size = 46   spacing = 0 蓝色为像素字 红色为普通ASS字。

很明显GDIfont的定位偏差极小 不死盯着看基本是看不到偏差。再次提醒一下使用GDIfont生成像素字或者是mask文字的时候
tcc文件中 font size:推荐用偶数(如果要用字大小30,40这种情况的话建议都加上2)spacing :设置为0

注:使用GDIfont mask文字原大小应设置为4 如:clip2(4, mask) 详情见工程文件。

最后使用GDIfont模块请更新以下两个文件:
tcaxPy.rar (6.53 KB, 下载次数: 1604)
gdiFont.rar (6.17 KB, 下载次数: 1606)

以下是工程文件例子:
GDIfont_sample.rar (1.11 MB, 下载次数: 1582)

注: 以上GDIfont模块文件可以不用下载 直接更新tcax到1.2.0版本就行     本文档以及附件例子中TCC文件字间距均设置为0
=========================================================
终于写完了呼呼呼……
有啥问题跟帖留言吧
牛奶大之前发的那个GDIfont.pyd 压缩文件里面不含更新后的tcaxpy 请大家下载好tcaxpy替换掉
原来的tcaxpy……


Administrator

TCAX Dev.

Rank: 7Rank: 7Rank: 7

发表于 2012-4-28 13:37:25 |显示全部楼层
辛苦了.

大致浏览了下,
font size:推荐用偶数(如果要用字大小30,40这种情况的话建议都加上2)
spacing :设置为0

可以改为
font size:推荐用偶数(如果要用字大小31,41这种情况的话建议都改为30, 40或32, 42)
spacing :设置为0, (或偶数, 2, 4, 6...). 并且在计算dx的时候用(_a + _spacing) / 2 代替 原来的_a, 其中_spacing = GetVal(val_Spacing), 此修正公式可参考 http://www.tcax.org/forum.php?mod=viewthread&tid=177



您需要登录后才可以回帖 登录 | 新人加入

GitHub|TCAX 主页

GMT+8, 2024-4-19 10:04

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部
RealH