| 
UID9积分4251帖子293主题40论坛币8464 威望29 EP值1646 MP值8 阅读权限100注册时间2011-8-3在线时间151 小时最后登录2022-8-8
 
  
 | 
| 本帖最后由 四月一日 君寻 于 2012-8-5 20:26 编辑 
 第一次写这种使用方法 写的不好请轻轻的喷哈……
 
 感谢牛奶大 辛苦了 终于把这个坑给填了
 .gif)  
 首先来说一下GDIfont模块是用来干嘛的吧 就素弥补  普通像素字  对  普通ASS文字  的定位偏差的。本文档用  GDI像素字代码  当做范例,mask 在完整工程中会有提供所以不做讲解。
 
 1.像素字py脚本的设置(GDI像素字代码与freetype的比较)见以下代码:
 
 复制代码from tcaxPy import *
from gdiFont import *  #加入GDIfont模块
def tcaxPy_Init():
    global _Fs
    #global _Font
    
    global GdiFont   #GDIfont
    
    _Fs = GetVal(val_FontSize)  
    fontFileName = GetVal(val_FontFileName)  
    faceID = GetVal(val_FaceID)             
    spacing = GetVal(val_Spacing)       
    spaceScale = GetVal(val_SpaceScale)
    color = MakeRGB(255, 255, 255)
    bord = 0         
    isOutline = False     
    #_Font = InitFont(fontFileName, faceID, _Fs, spacing, spaceScale, color, bord, isOutline)
    
    GdiFont = gfInitFont(GetVal(val_FontFaceName), _Fs, GetVal(val_Spacing), GetVal(val_SpaceScale), 0, False)   #GDIfont
def tcaxPy_Fin():
    #FinFont(_Font) 
     
    gfFinFont(GdiFont)   #GDIfont
def tcaxPy_Main(_i, _j, _n, _start, _end, _elapk, _k, _x, _y, _a, _txt):
    ASS_BUF  = []     
    TCAS_BUF = []
    ass_main(ASS_BUF, SubL(_start, _end, 0,), pos(_x, _y) + color1('0000FF')+bord(0)+shad(0), _txt)
    
    points = gfGetPoints(GdiFont, _txt)  #GDIfont
    PIX = PixFromPoints(points)   #GDIfont
    
    #PIX = TextPix(_Font, _txt)
    initPosX = _x - int(_a / 2 + 0.5) + PIX[0][0]   
    initPosY = _y - int(_Fs / 2 + 0.5) + PIX[0][1]     
    for h in range(PIX[1][1]):                        
        posY = initPosY + h                     
        for w in range(PIX[1][0]):                  
            posX = initPosX + w                     
            idx  = 4 * (h * PIX[1][0] + w)          
            pixR = PIX[2][idx + 0]                 
            pixG = PIX[2][idx + 1]             
            pixB = PIX[2][idx + 2]             
            pixA = PIX[2][idx + 3]             
            if pixA != 0:             
                ass_main(ASS_BUF, SubL(_start, _end, 0, Pix_Style), pos(posX, posY) + color1('FF5E00') + alpha1(255 - pixA), PixPt())
    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文件:
 
 复制代码# tcc file version
< tcc file version = 1.0 >
# mode configuration
< inherit ass header = false >
< k mode = syl >
< text layout = horizontal >
< tcaxpy init = true >
< tcaxpy user = false >
< tcaxpy fin = true >
# py settings
< py file = ceshiGDIfontlizi.py >    < beg line = 1 >    < end line = 0 >
# main settings
< k-timed ass file = ceshi_k.ass >
< font file = epkgobld_1.ttf >    < font face id = 1 >    < font size = 46 >
< fx width = 1280 >    < fx height = 720 >    < fx fps = 23.976 >
< alignment = 2 >
< x offset = 10 >    < y offset = 10 >
< spacing = 0 >    < space scale = 0.5 >
# style settings
< font face name = "" >
< bord = 2 >    < shad = 0 >
< primary color = 9393FF >    < secondary color = FFFFFF >    < outline color = FFFFFF >    < back color = FFFFFF >
< primary alpha = 0 >    < secondary alpha = 255 >    < outline alpha = 0 >    < back alpha = 255 >
# additional settings
< blur = 0.0 >
3.以下是 freetype,GDI,tcc设置不同的对比图:
 
 1:freetype字体引擎生成的像素字与ASS普通字:
 
  蓝色为像素字 红色为普通ASS字。 
 2:GDI字体引擎生成的像素字语ASS普通字:
 
  蓝色为像素字 红色为普通ASS字。 
 3:使用GDIfont模块tcc文件的设置不同:
 
  TCC中 font size = 45   spacing = 1 蓝色为像素字 红色为普通ASS字。 
 
 
  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, 下载次数: 3722) 
  gdiFont.rar
(6.17 KB, 下载次数: 3721) 
 以下是工程文件例子:
 
  GDIfont_sample.rar
(1.11 MB, 下载次数: 3790) 
 注: 以上GDIfont模块文件可以不用下载 直接更新tcax到1.2.0版本就行     本文档以及附件例子中TCC文件字间距均设置为0
 =========================================================
 终于写完了呼呼呼……
 有啥问题跟帖留言吧
 牛奶大之前发的那个GDIfont.pyd 压缩文件里面不含更新后的tcaxpy 请大家下载好tcaxpy替换掉
 原来的tcaxpy……
 
 
 
 | 
 |