Advertisement
teadrinker

Титры

May 16th, 2011
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. MaxSigns = 20  ; заменить на нужное
  2. watchfolder = %A_Desktop%\watchfolder ; заменить на истинный путь к папке с файлами титров
  3. prtlPath = %A_Desktop%\1.prtl  ; заменить на истинный путь к исходному файлу 1.ptrl
  4. FontName = Arial   ; заменить на нужный
  5. FontSize = 10   ; заменить на нужный
  6.  
  7. FileEncoding, UTF-16
  8. FileRead, prtl, %prtlPath%
  9. Return
  10. F11::
  11. i := n := PrevEndPos := 1
  12.  
  13. FileRemoveDir, %watchfolder%, 1
  14. FileCreateDir, %watchfolder%
  15. ClipBoard =
  16. SendInput, ^{vk43}   ; Ctrl + C
  17. ClipWait, 2
  18. if ErrorLevel
  19. {
  20.    MsgBox, Буфер обмена пуст!
  21.    Return
  22. }
  23. Clipboard := RegExReplace(Clipboard, "\R+", "`n")
  24. Length := StrLen(Clipboard)
  25. Loop, parse, ClipBoard
  26. {
  27.    if (A_Index = Length)
  28.       EndPos := A_Index + 1
  29.    if (A_LoopField = " " || A_LoopField = "`n")
  30.       EndPos := A_Index
  31.    if (A_Index = Length || A_LoopField = "`n" || i = MaxSigns + 1)
  32.    {
  33.       if !EndPos
  34.          EndPos := A_Index + 1, Modifier := 1
  35.       String%n% := SubStr(ClipBoard, PrevEndPos, EndPos - PrevEndPos)
  36.       if Modifier
  37.          PrevEndPos := EndPos, Modifier := ""
  38.       Else
  39.          PrevEndPos := EndPos + 1
  40.       i := A_Index - EndPos, n++, EndPos := ""
  41.    }
  42.    i++
  43. }
  44.  
  45. Loop % n - 1
  46. {
  47. ;   MsgBox, % "String" A_Index " = |" String%A_Index% "|"
  48.    String := String%A_Index%
  49.    StrLength := StrLen(String) + 1
  50.    nSise := GetTextExtentPoint(String, FontName, FontSize)
  51.    StrWidth := nSise & 0xFFFFFFFF
  52.    Pos := Round((720 - StrWidth)/2)
  53.    
  54.    prtl%A_Index% := RegExReplace(prtl, "<CharacterAttributes RunCount="".*?"""
  55.                                      , "<CharacterAttributes RunCount=""" StrLength """")
  56.    
  57.    prtl%A_Index% := RegExReplace(prtl%A_Index%, "<TRString>.*?</TRString>"
  58.                                               , "<TRString>" String "</TRString>")
  59.                                              
  60.    prtl%A_Index% := RegExReplace(prtl%A_Index%, "<XPos>.*?</XPos>"
  61.                                               , "<XPos>" Pos "</XPos>")
  62.    FileName := "title" . SubStr("000", 1, -(StrLen(A_Index))) . A_Index . ".prtl"
  63.    FileAppend, % prtl%A_Index%, %watchfolder%\%FileName%
  64. }
  65.  
  66. MsgBox, Сделано!
  67. Return
  68.  
  69. GetTextExtentPoint(sString, sFaceName, nHeight = 9
  70.    , bBold = False, bItalic = False, bUnderline = False, bStrikeOut = False, nCharSet = 0)
  71. {
  72.    hDC := DllCall("GetDC", "Uint", 0)
  73.    nHeight := -DllCall("MulDiv", "int", nHeight
  74.                                , "int", DllCall("GetDeviceCaps", "Uint", hDC, "int", 90)
  75.                                , "int", 72)
  76.  
  77.    hFont := DllCall("CreateFont", "int", nHeight, "int", 0, "int", 0, "int", 0
  78.                                 , "int", 400 + 300 * bBold, "Uint", bItalic
  79.                                 , "Uint", bUnderline, "Uint", bStrikeOut, "Uint", nCharSet
  80.                                 , "Uint", 0, "Uint", 0, "Uint", 0, "Uint", 0, "str", sFaceName)
  81.    hFold := DllCall("SelectObject", "Uint", hDC, "Uint", hFont)
  82.  
  83.    DllCall("GetTextExtentPoint32", "Uint", hDC, "str", sString, "int", StrLen(sString), "int64P", nSize)
  84.  
  85.    DllCall("SelectObject", "Uint", hDC, "Uint", hFold)
  86.    DllCall("DeleteObject", "Uint", hFont)
  87.    DllCall("ReleaseDC", "Uint", 0, "Uint", hDC)
  88.  
  89.    Return nSize
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement