- UID
- 2
- 积分
- 8682
- 帖子
- 2905
- 主题
- 199
- 论坛币
- 11741
- 威望
- 16
- EP值
- 2349
- MP值
- 15
- 阅读权限
- 200
- 注册时间
- 2011-8-3
- 在线时间
- 2597 小时
- 最后登录
- 2024-8-28
|
补充示例, 参考模板- from tcaxPy import *
- from util.cairo import *
- def tcaxPy_User():
- GetHelp() # get the description of the global variables, comment them if you don't need
- # initilization
- file_name = GetVal(val_OutFile) + '.tcas'
- fx_width = GetVal(val_ResolutionX)
- fx_height = GetVal(val_ResolutionY)
- fx_fps = GetVal(val_FXFPS)
- TCAS_FILE = CreateTcasFile(file_name, fx_width, fx_height, fx_fps)
- surface = ImageSurface(FORMAT_ARGB32, fx_width, fx_height)
- ctx = Context(surface)
- Font = InitFont(GetVal(val_FontFileName), GetVal(val_FaceID), GetVal(val_FontSize), GetVal(val_Spacing), GetVal(val_SpaceScale), HexToDec(GetVal(val_1C)), GetVal(val_Bord), False)
- # retrieve basic information
- FD = 1000 / fx_fps
- fontSize = GetVal(val_FontSize)
- marginX = GetVal(val_OffsetX)
- marginY = GetVal(val_OffsetY)
- spacing = GetVal(val_Spacing)
- lineNum = GetVal(val_nLines)
- textNum = GetVal(val_nTexts)
- start = GetVal(val_BegTime)
- end = GetVal(val_EndTime)
- kar = GetVal(val_KarTime)
- elapKar = GetVal(val_KarTimeDiff)
- text = GetVal(val_Text)
- textLength = GetVal(val_TextLength)
- width = GetVal(val_TextWidth)
- height = GetVal(val_TextHeight)
- advance = GetVal(val_TextAdvance)
- advDiff = GetVal(val_TextAdvanceDiff)
- # main loop
- for i in range(lineNum):
- initPosX = (fx_width - textLength[i]) / 2 + marginX # if marginX = 0, then it's just on the middle
- initPosY = fx_height - fontSize - marginY
- for j in range(textNum[i]):
- if text[i][j] == '' or text[i][j] == ' ' or text[i][j] == ' ':
- continue
- posX = initPosX + advDiff[i][j] + advance[i][j] / 2
- posY = initPosY
- # draw by Cairo Toy Font API, color is pink, without border
- ctx.select_font_face(GetVal(val_FontFaceName))
- ctx.set_font_size(fontSize)
- ctx.move_to(posX, posY + fontSize + GetVal(val_Descender))
- ctx.text_path(text[i][j])
- ctx.set_source_rgb(1, 0, 1)
- ctx.fill()
- # draw by tcaxLib TextOutlineDraw API, color is red, without border
- ctx.save()
- ctx.scale(1 / 64, 1 / 64)
- outline = TextOutlineDraw(Font, text[i][j], posX, posY)
- AssDraw(ctx, outline)
- ctx.set_source_rgb(1, 0, 0)
- ctx.fill()
- ctx.restore()
- # draw by tcaxLib TextPix API, color is blue, with border = 1 (according to the setting of the TCC file)
- TCAS_BUF = []
- PIX = TextPix(Font, text[i][j])
- PIX = PixColorRGB(PIX, MakeRGB(0, 0, 0))
- tcas_main(TCAS_BUF, PIX, start[i] * 10, end[i] * 10, posX, posY, 0)
- WriteTcasFile(TCAS_FILE, TCAS_BUF)
- # you can also draw the text by ASS, through various methods, such as direct text, draw by ASS drawing commands or draw by pixels, and hopefully note that all kinds of text drawing will likely to produce the same result, cool huh :)
- # the result of this script is that lines of red texts with blue borders, let me explain, the pink texts are covered by the red one, since they comes later and on the same layer, the blue ones are written to the TCAS file earliest, but they have border! So you can see them
- TCAS_BUF = []
- PIX = surface.get_pix()
- surface_clear(ctx)
- PIX = PixStrip(PIX)
- tcas_main(TCAS_BUF, PIX, start[i] * 10, end[i] * 10, 0, 0, 0)
- WriteTcasFile(TCAS_FILE, TCAS_BUF) # write the buffer in memory to the file
- progress(i + 1, lineNum)
- FinFont(Font)
- FinTcasFile(TCAS_FILE)
复制代码 |
|