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

 找回密码
 新人加入
查看: 6134|回复: 4
打印 上一主题 下一主题

[已解决] border_pixels! [复制链接]

Rank: 4

跳转到指定楼层
楼主
发表于 2013-11-9 13:46:07 |只看该作者 |倒序浏览
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 ?

Administrator

Shanzhai Pro.

Rank: 7Rank: 7Rank: 7

沙发
发表于 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):

Rank: 4

板凳
发表于 2013-11-12 14:14:42 |只看该作者
hmmm. I didn't get you
do I have to focus what written in red color?

Administrator

TCAX Dev.

Rank: 7Rank: 7Rank: 7

地板
发表于 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)
复制代码

Administrator

TCAX Dev.

Rank: 7Rank: 7Rank: 7

5#
发表于 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

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

GitHub|TCAX 主页

GMT+8, 2024-12-12 05:27

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部
RealH