Advertisement
teadrinker

Титры 5

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