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

标题: border_pixels! [打印本页]

作者: Alex    时间: 2013-11-9 13:46:07     标题: border_pixels!

Is there way that we can do a border pixels?

like convert text to shape (border only), after that convert border shape to pixel ?
so after that we can get a border pixel only ?
作者: saiyaku    时间: 2013-11-9 17:10:39

## Initialize a font and retrieves a PIX of the specified text from the font.
# @param font_file a string, filename of the target font file
# @param face_id an integer, font face id, should always be 1 in TTF files
# @param font_size an integer, font size, in em height
# @param spacing an integer, spacing between texts, can be negative
# @param space_scale a float, scale of white spaces
# @param color an integer, rgb color of the font
# @param bord an integer, border of the font, can be negative
# @param is_outline an integer, 0 - include body, 1 - only retrieve the outline
# @param text a string, the text that is going to generate a PIX
# @return PIX the target PIX
def TextPix(font_file, face_id, font_size, spacing, space_scale, color, bord, is_outline, text):

## Retrieve a PIX of the specified text from a font.
# @param font a handler, the handler to the font
# @param text a string, the text that is going to generate a PIX
# @return PIX the target PIX
def TextPix(font, text):


## Get text outline points.  (outline curve to points in order)
# @param font_file a string, filename of the target font file
# @param face_id an integer, font face id, should always be 1 in TTF files
# @param font_size an integer, font size, in em height
# @param text a string, the text of which the outline will be retrieved
# @param density a float, the density of points that we want to have, 1.0 is commonly used, however it can be less or larger than 1 according to the need
# @return ((x1, y1), (x2, y2), ...)
def TextOutlinePoints(font_file, face_id, font_size, text, density):

## Get text outline points.
# @param font a handler, the handler to the font
# @param text a string, the text of which the outline will be retrieved
# @param density a float, the density of points that we want to have, 1.0 is commonly used, however it can be less or larger than 1 according to the need
# @return ((x1, y1), (x2, y2), ...)
def TextOutlinePoints(pyFont, text, density):
作者: Alex    时间: 2013-11-12 14:14:42

hmmm. I didn't get you
do I have to focus what written in red color?
作者: milkyjing    时间: 2013-11-12 22:43:25

Alex 发表于 2013-11-12 14:14
hmmm. I didn't get you
do I have to focus what written in red color?

yes, focus on the text in red, indeed, there are two kinds of functions, to get a PIX structure that only contain the boarder pixels, the other, get points of the boarder.

below is a demo of usage of TextOutlinePoints.
  1. from tcaxPy import *

  2. def tcaxPy_Init():
  3.     global _Fs
  4.     global Font
  5.     _Fs = GetVal(val_FontSize)
  6.     Font = InitFont(GetVal(val_FontFileName), GetVal(val_FaceID), _Fs, GetVal(val_Spacing), GetVal(val_SpaceScale), 0xFFFFFF, 0, 0)

  7. def tcaxPy_Fin():
  8.     FinFont(Font)

  9. def tcaxPy_Main(_i, _j, _n, _BT, _ET, _SK, _KT, _X, _Y, _A, _TXT):

  10.     ASS_BUF = []
  11.     TCS_BUF = []

  12.     ass_main(ASS_BUF, SubL(_BT + 200, _ET), pos(_X, _Y) + color1('00FFFF') + bord(0) + blur(4) + fad(400, 0), _TXT)

  13.     dx = _X - int(_A / 2 + 0.5)
  14.     dy = _Y - int(_Fs / 2 + 0.5)
  15.     outline = TextOutlinePoints(Font, _TXT, 1.0)
  16.     num = len(outline)
  17.     dur = 200
  18.     for i in range(num):
  19.         ts = _BT + dur * i / num
  20.         te = _ET
  21.         x = dx + outline[i][0]
  22.         y = dy + outline[i][1]
  23.         EFT = pos(x, y) + alpha1(0) + alpha3(150) + alpha4(200) + bord(1) + shad(1) + be(1) + \
  24.               color1('0000FF') + color3('FF00FF') + color4('FFFF00') + fad(200, 0)
  25.         ass_main(ASS_BUF, SubL(ts, te, 1, Pix_Style), EFT, PixPt())

  26.     return (ASS_BUF, TCS_BUF)
复制代码

作者: milkyjing    时间: 2013-11-12 22:52:04

Alex 发表于 2013-11-12 14:14
hmmm. I didn't get you
do I have to focus what written in red color?

moreover, PIX object can be converted to Points object, vice versa.
  1. FontOut = InitFont(_FontFileName, _FaceID, _Fs, _Spacing, GetVal(val_SpaceScale), 0xFFFFFF, 3, True)
  2. PIX = TextPix(FontOut, _txt)
复制代码
the PIX will contain pixels that shows a text whose boarder is 3, and with main structure hollowed.

you can use the following code to debug
  1. SavePix(abspath("pix.png"), PIX)
  2. Pause()
复制代码
btw, by using tcax's drawing utility, the cairo module, you can convert any vectorial drawing into pixels bitmaps. for your ref. http://www.tcax.org/forum.php?mod=viewthread&tid=208






欢迎光临 TCAX 字幕特效制作工具官方论坛 | ASS | TCAS | Python | Aegisub | Lua (http://tcax.org/) Powered by Discuz! X2