Advertisement
teadrinker

Титры 3

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