1. --*************************************************************************
  2. -- Script: PRINT_CLASS
  3. -- @Version 0.2
  4. -- @Author Valentin Schmidt
  5. -- @Created 19.06.2009
  6. -- @Modified 22.07.2009
  7. --
  8. -- @Description
  9. -- This script implements printing based on flash.
  10. --
  11. -- Usage:
  12. --  p = script("PRINT_CLASS").new()
  13. --  p.mAddPage()
  14. --  p.mAddText("Hello World!", 50, 50, 100)
  15. --  p.mPrint()
  16. --  p.mDestroy()
  17. --  p=0
  18. --
  19. -- @Dependencies
  20. -- # (empty) flash 8 sprite with scaleMode=#noScale
  21. --
  22. -- @History
  23. --
  24. -- v0.1
  25. -- First version
  26. --
  27. -- v0.2
  28. -- minor bug fix
  29. --
  30. --**************************************************************************
  31.  
  32. -- public
  33. property pPageCnt
  34. property pCurrentPageNum
  35.  
  36. -- internal
  37. property pFlashSprite
  38. property pPageFormat
  39. property pPrintArea
  40. property pMcCnt
  41. property pCurrentPage
  42. property pPrintAsBitmap
  43. property pBitmaps
  44.  
  45. -- settings
  46. property pFillColor
  47. property pFillAlpha
  48. --property pFillStyle ???
  49.  
  50. property pTextFormat
  51. property pLineStyle
  52. property pAutoPageBreak
  53. property pMargins
  54. property pBreakChars
  55.  
  56. ----------------------------------------
  57. -- Constructor
  58. -- @param sprite tFlashSprite: a flash sprite reference (flash 8 movie, can be empty)
  59. -- @param list|string tPageFormat: (optional) either a list [widthInPt, heightInPt] or one of the following strings: "A3", "A4"(=default), "A5", "letter", "legal"
  60. -- @param string tOrientation: (optional) "L" for landscape or "P" for portrait (=default)
  61. ----------------------------------------
  62. on new (me,tFlashSprite, tPageFormat, tOrientation)
  63.   pFlashSprite = tFlashSprite
  64.   if not listP(tPageFormat) then tPageFormat = "A4"
  65.  
  66.   case (tPageFormat) of
  67.     "A3":
  68.       tPageFormat=[842.0, 1191.0] -- 841.89, 1190.55
  69.     "A4":
  70.       tPageFormat=[595.0, 842.0] -- 595.28, 841.89
  71.     "A5":
  72.       tPageFormat=[421.0, 595.0] -- 420.94, 595.28
  73.     "letter":
  74.       tPageFormat=[612.0, 792.0]
  75.     "legal":
  76.       tPageFormat=[612.0, 1008.0]
  77.   end case
  78.  
  79.  
  80.   if tOrientation="L" then
  81.     pPageFormat = [tPageFormat[2], tPageFormat[1]] -- Landscape
  82.   else
  83.     pPageFormat = tPageFormat -- default: Portrait
  84.   end if
  85.  
  86.   pPrintArea = pFlashSprite.newObject("Object")
  87.   pPrintArea.xMin = 0
  88.   pPrintArea.xMax = pPageFormat[1]
  89.   pPrintArea.yMin = 0
  90.   pPrintArea.yMax = pPageFormat[2]  
  91.  
  92.   -- TEXT
  93.   pTextFormat = [:]
  94.   pTextFormat["color"] = "0x000000"
  95.   pTextFormat["font"] = "Arial"
  96.   pTextFormat["size"] = 11
  97.  
  98.   -- FILL
  99.   pFillColor = "0x000000"
  100.   pFillAlpha = 100
  101.  
  102.   -- DRAW  
  103.   pLineStyle = [:]
  104.   pLineStyle["thickness"] = 1
  105.   pLineStyle["rgb"] = "0x000000"
  106.   pLineStyle["alpha"] = 100
  107.   pLineStyle["pixelHinting"] = 0
  108.   pLineStyle["noScale"] = "normal"
  109.   pLineStyle["capsStyle"] = "round"
  110.   pLineStyle["jointStyle"] = "round"
  111.   pLineStyle["miterLimit"] = 3
  112.  
  113.  
  114.   -- AUTO PAGE BREAK
  115.   pAutoPageBreak = 0
  116.   pBreakChars = [SPACE, "-", ".", ",",";"]
  117.  
  118.   -- internal
  119.   pPageCnt = 0
  120.   pCurrentPageNum = 0
  121.   pCurrentPage = VOID
  122.   pBitmaps = []
  123.   pMcCnt = 0
  124.   pPrintAsBitmap = []
  125.  
  126.   pMargins = [#left: 28, #top: 28, #right:28, #bottom:28] -- 28 pt = 2 cm
  127.   return me
  128. end
  129.  
  130. ----------------------------------------
  131. -- Safely deletes object, releases memory
  132. ----------------------------------------
  133. on mDestroy (me)
  134.  
  135.   cnt = count(pBitmaps)
  136.   repeat with i = cnt down to 1
  137.     pBitmaps[i].dispose() -- ???
  138.     pBitmaps.deleteAt(i)
  139.   end repeat
  140.  
  141.   repeat with i = 1 to pPageCnt
  142.     pFlashSprite["page"&i].clear() -- ???
  143.     pFlashSprite["page"&i].removeMovieClip()
  144.   end repeat
  145.  
  146.   pPageCnt = 0
  147.   pCurrentPageNum = 0
  148. end
  149.  
  150. --**************************************
  151. -- PUBLIC
  152. --**************************************
  153.  
  154. ----------------------------------------
  155. -- Sets page margins
  156. -- @param propList tMargins: propList containing one or more of the following properties: #left, #right, #top, #bottom
  157. -- margins are specified as floats
  158. ----------------------------------------
  159. on mSetMargins (me, tMargins)
  160.   cnt = tMargins.count
  161.   repeat with i = 1 to cnt
  162.     pMargins[tMargins.getPropAt(i)] = tMargins[i]
  163.   end repeat
  164. end
  165.  
  166. ----------------------------------------
  167. -- (De)Activates autoPageBreak
  168. -- @param integer tBool
  169. ----------------------------------------
  170. on mSetAutoPageBreak (me, tBool)
  171.   pAutoPageBreak = tBool
  172. end
  173.  
  174. ----------------------------------------
  175. -- Adds a new page to the document
  176. ----------------------------------------
  177. on mAddPage (me)
  178.   pPageCnt = pPageCnt + 1
  179.   pCurrentPage = pFlashSprite.createEmptyMovieClip("page"&pPageCnt, pFlashSprite.getNextHighestDepth())
  180.   pCurrentPageNum = pPageCnt
  181.  
  182.   me.mHeader()
  183.   me.mFooter()
  184. end
  185.  
  186. ----------------------------------------
  187. -- Changes the active page
  188. -- @param integer tPageNum
  189. ----------------------------------------
  190. on mSetActivePage (me, tPageNum)
  191.   pCurrentPage = pFlashSprite["page"&tPageNum]
  192.   pCurrentPageNum = tPageNum
  193. end
  194.  
  195. ----------------------------------------
  196. -- Adds a text to the document at the specified position
  197. -- @param string tText: can be plain text or html. To use html, pass ["html":1, ....] as tSettings parameter. See {@link html.htm} for supported HTML tags.
  198. -- @param integer tX
  199. -- @param integer tY
  200. -- @param integer tW
  201. -- @param integer tH: (optional)
  202. -- @param propList tSettings: (optional) propList of setting-values. See {@link settings.htm settings.htm} for a list of supported values.
  203. -- @param propList|string tFormat: (optional) propList of setting-values or a CSS string. See {@link format.htm format.htm} and {@link css.htm css.htm} for lists of supported values.
  204. --
  205. -- @return float y-position of text bottom
  206. ----------------------------------------
  207. on mAddText (me, tText, tX, tY, tW, tH, tSettings, tFormat)
  208.   if voidP(tSettings) then tSettings=[:]
  209.   if voidP(tH) or tH=0 then tH=pPageFormat[2]
  210.  
  211.   mc = pCurrentPage.createTextField(me._getMcName(), pCurrentPage.getNextHighestDepth(), tX, tY, tW, tH)
  212.  
  213.   cnt = tSettings.count
  214.   repeat with i = 1 to cnt
  215.     mc[tSettings.getPropAt(i)] = tSettings[i]
  216.   end repeat
  217.  
  218.   fmt = pFlashSprite.newObject("TextFormat")
  219.  
  220.   -- defaults
  221.   cnt = pTextFormat.count
  222.   repeat with i = 1 to cnt
  223.     fmt[pTextFormat.getPropAt(i)] = pTextFormat[i]
  224.   end repeat
  225.  
  226.   if ilk(tFormat)=#propList then
  227.     cnt = tFormat.count
  228.     repeat with i = 1 to cnt
  229.       fmt[tFormat.getPropAt(i)] = tFormat[i]
  230.     end repeat
  231.   end if
  232.  
  233.   mc.setNewTextFormat(fmt)
  234.  
  235.   if ilk(tFormat)=#string then
  236.     my_styleSheet = pFlashSprite.newObject("TextField.StyleSheet")
  237.     my_styleSheet.parseCSS(tFormat)
  238.     mc.styleSheet = my_styleSheet
  239.   end if
  240.  
  241.   if tSettings["html"] then
  242.     mc.html = true
  243.     mc.htmlText = tText
  244.   else
  245.     mc.html = false
  246.     mc.text = tText
  247.   end if
  248.  
  249.   if pAutoPageBreak then
  250.    
  251.     maxH = pPageFormat[2]-pMargins[#bottom]-tY
  252.    
  253.     if mc._height>maxH then
  254.      
  255.       -- FIND MAX. FITTING TEXT
  256.       maxFit = 0
  257.       n = 160
  258.       len = tText.length
  259.       cnt = len/n
  260.       repeat with i = 1 to cnt
  261.         mc.text = tText.char[1..i*n]
  262.         if mc._height>maxH then
  263.           maxFit = i*n-1
  264.           exit repeat
  265.         end if
  266.       end repeat
  267.      
  268.       if maxFit=0 then
  269.         repeat with i = n*cnt to len
  270.           mc.text = tText.char[1..i]
  271.           if mc._height>maxH then
  272.             maxFit = i-1
  273.             exit repeat
  274.           end if
  275.         end repeat
  276.       end if
  277.      
  278.       if maxFit>0 then
  279.        
  280.         repeat with i = maxFit down to 1
  281.           if pBreakChars.getPos(tText.char[i]) then
  282.             mc.text = tText.char[1..i]
  283.             if mc._height<=maxH then
  284.               maxFit = i
  285.               exit repeat
  286.             end if
  287.           end if
  288.         end repeat
  289.        
  290.         me.mAddPage()
  291.        
  292.         tY = pMargins[#top]
  293.         return me.mAddText(tText.char[maxFit+1..tText.length], tX, tY, tW, tH, tSettings, tFormat)
  294.         --return tY + mc._height
  295.        
  296.       else
  297.         put "ERROR"
  298.       end if
  299.      
  300.     end if
  301.    
  302.   end if
  303.  
  304.   return tY + mc.textHeight
  305. end
  306.  
  307. ----------------------------------------
  308. -- Returns width of string when printed with current/specified format
  309. -- @param string tText
  310. -- @param propList tSettings: (optional) propList of setting-values
  311. -- @param propList|string tFormat: (optional) propList of setting-values or a CSS string
  312. --
  313. -- @return float
  314. --
  315. -- @see mAddText
  316. ----------------------------------------
  317. on mGetTextWidth (me, tText, tSettings, tFormat)
  318.   if voidP(tSettings) then tSettings=[:]
  319.  
  320.   mc = pCurrentPage.createTextField(me._getMcName(), pCurrentPage.getNextHighestDepth(), 0, 0, 1000, 1000)
  321.  
  322.   cnt = tSettings.count
  323.   repeat with i = 1 to cnt
  324.     mc[tSettings.getPropAt(i)] = tSettings[i]
  325.   end repeat
  326.  
  327.   fmt = pFlashSprite.newObject("TextFormat")
  328.  
  329.   -- defaults
  330.   cnt = pTextFormat.count
  331.   repeat with i = 1 to cnt
  332.     fmt[pTextFormat.getPropAt(i)] = pTextFormat[i]
  333.   end repeat
  334.  
  335.   if ilk(tFormat)=#propList then
  336.     cnt = tFormat.count
  337.     repeat with i = 1 to cnt
  338.       fmt[tFormat.getPropAt(i)] = tFormat[i]
  339.     end repeat
  340.   end if
  341.  
  342.   mc.setNewTextFormat(fmt)
  343.  
  344.   if ilk(tFormat)=#string then
  345.     my_styleSheet = pFlashSprite.newObject("TextField.StyleSheet")
  346.     my_styleSheet.parseCSS(tFormat)
  347.     mc.styleSheet = my_styleSheet
  348.   end if
  349.  
  350.   --mc.wordWrap = 0 -- ???
  351.  
  352.   if tSettings["html"] then
  353.     mc.html = true
  354.     mc.htmlText = tText
  355.   else
  356.     mc.html = false
  357.     mc.text = tText
  358.   end if
  359.  
  360.   w = mc.textWidth
  361.   mc.removeTextField()
  362.  
  363.   return w
  364. end
  365.  
  366. ----------------------------------------
  367. -- Adds an image to the document at the specified position
  368. -- @param image tImage
  369. -- @param integer tX
  370. -- @param integer tY
  371. -- @param integer tW: (optional)
  372. -- @param integer tH: (optional)
  373. -- @param propList tSettings: (optional)
  374. ----------------------------------------
  375. on mAddImage (me, tImage, tX, tY, tW, tH, tSettings)
  376.   if voidP(tW) then tW = tImage.width
  377.   if voidP(tH) then tH = tW * tImage.height/tImage.width
  378.   if voidP(tSettings) then tSettings=[:]
  379.  
  380.   myBitmapData = pFlashSprite.convert(#BitmapData, tImage)
  381.   pBitmaps.add(myBitmapData)
  382.  
  383.   mc = pCurrentPage.createEmptyMovieClip(me._getMcName(), pCurrentPage.getNextHighestDepth() )
  384.  
  385.   -- public attachBitmap(bmp:BitmapData, depth:Number, [pixelSnapping:String], [smoothing:Boolean]) : Void
  386.   mc.attachBitmap(myBitmapData, 1)
  387.  
  388.   mc._x = tX
  389.   mc._y = tY
  390.   mc._width = tW
  391.   mc._height = tH
  392.  
  393.   cnt = tSettings.count
  394.   repeat with i = 1 to cnt
  395.     mc[tSettings.getPropAt(i)] = tSettings[i]
  396.   end repeat
  397.  
  398.   --myBitmapData.dispose() -- ???
  399.  
  400.   if pPrintAsBitmap.getPos(pCurrentPageNum)=0 then pPrintAsBitmap.add(pCurrentPageNum)
  401. end
  402.  
  403. --**************************************
  404. -- SETTINGS
  405. --**************************************
  406.  
  407. ----------------------------------------
  408. -- Sets the draw color
  409. -- @param color tColor
  410. ----------------------------------------
  411. on mSetDrawColor (me, tColor)
  412.   pLineStyle["rgb"] = "0x" & tColor.hexString().char[2..7]
  413. end
  414.  
  415. ----------------------------------------
  416. -- Sets the fill color
  417. -- @param color tColor
  418. ----------------------------------------
  419. on mSetFillColor (me, tColor)
  420.   pFillColor = "0x" & tColor.hexString().char[2..7]
  421. end
  422.  
  423. ----------------------------------------
  424. -- Sets the fill alpha value
  425. -- @param integer tAlpha: 0=transparent, 100=opaque
  426. ----------------------------------------
  427. on mSetFillAlpha (me, tAlpha)
  428.   pFillAlpha = tAlpha
  429. end
  430.  
  431. ----------------------------------------
  432. -- Sets the default text format for all text
  433. -- @param propList tFormat: propList of format-values (as flash-style); see "format.htm" for list of supported values
  434. ----------------------------------------
  435. on mSetTextFormat (me, tFormat)
  436.   cnt = tFormat.count
  437.   repeat with i = 1 to cnt
  438.     pTextFormat[tFormat.getPropAt(i)] = tFormat[i]
  439.   end repeat
  440. end
  441.  
  442. ----------------------------------------
  443. -- Sets the text color
  444. -- @param color tColor
  445. ----------------------------------------
  446. on mSetTextColor (me, tColor)
  447.   pTextFormat["color"] = "0x" & tColor.hexString().char[2..7]
  448. end
  449.  
  450. ----------------------------------------
  451. -- Sets the font
  452. -- @param string tFont
  453. ----------------------------------------
  454. on mSetFont (me, tFont)
  455.   pTextFormat["font"] = tFont
  456. end
  457.  
  458. ----------------------------------------
  459. -- Sets the fontsize
  460. -- @param float tFontSize
  461. ----------------------------------------
  462. on mSetFontSize (me, tFontSize)
  463.   pTextFormat["size"] = tFontSize
  464. end
  465.  
  466. ----------------------------------------
  467. -- Sets the linestyle
  468. -- @param propList tLineStyle: supported properties: thickness:Number, rgb:Number, alpha:Number, pixelHinting:Boolean, noScale:String, capsStyle:String, jointStyle:String, miterLimit:Number
  469. ----------------------------------------
  470. on mSetLineStyle (me, tLineStyle)
  471.   cnt = tLineStyle.count
  472.   repeat with i = 1 to cnt
  473.     pLineStyle[tLineStyle.getPropAt(i)] = tLineStyle[i]
  474.   end repeat
  475. end
  476.  
  477.  
  478. --**************************************
  479. -- DRAW
  480. --**************************************
  481.  
  482. ----------------------------------------
  483. -- Draws a line
  484. -- @param integer tX1
  485. -- @param integer tY1
  486. -- @param integer tX2
  487. -- @param integer tY2
  488. -- @param propList tLineGradProps: (optional)
  489. ----------------------------------------
  490. on mAddLine (me, tX1, tY1, tX2, tY2, tLineGradProps)
  491.   mc = pCurrentPage.createEmptyMovieClip(me._getMcName(), pCurrentPage.getNextHighestDepth())
  492.  
  493.   me._setLineStyle(mc)
  494.   if listP(tLineGradProps) then
  495.     me._setGradientLineStyle(mc, tLineGradProps)
  496.   end if
  497.  
  498.   mc.moveTo(tX1, tY1)
  499.   mc.lineTo(tX2, tY2)
  500. end
  501.  
  502. ----------------------------------------
  503. -- Draws a rect
  504. -- @param integer tX
  505. -- @param integer tY
  506. -- @param integer tW
  507. -- @param integer tH
  508. -- @param string tStyle: (optional) "D" for draw (=default), "F" for fill, "DF" for both
  509. -- @param propList tLineGradProps: (optional)
  510. -- @param propList tFillGradProps: (optional)
  511. ----------------------------------------
  512. on mAddRect (me, tX, tY, tW, tH, tStyle, tLineGradProps, tFillGradProps)
  513.   if voidP(tStyle) then tStyle="D"
  514.   mc = pCurrentPage.createEmptyMovieClip(me._getMcName(), pCurrentPage.getNextHighestDepth())
  515.  
  516.   if tStyle contains "D" then
  517.     me._setLineStyle(mc)
  518.     if listP(tLineGradProps) then
  519.       me._setGradientLineStyle(mc, tLineGradProps)
  520.     end if
  521.   end if
  522.  
  523.   if tStyle contains "F" then
  524.     if listP(tFillGradProps) then
  525.       me._setGradientFill(mc, tFillGradProps)
  526.     else
  527.       mc.beginFill(pFillColor, pFillAlpha)
  528.     end if
  529.   end if
  530.  
  531.   mc.moveTo(tX, tY)
  532.   mc.lineTo(tX+tW, tY)
  533.   mc.lineTo(tX+tW, tY+tH)
  534.   mc.lineTo(tX, tY+tH)
  535.   mc.lineTo(tX, tY)
  536.   if tStyle contains "F" then mc.endFill()
  537. end
  538.  
  539. ----------------------------------------
  540. -- Draws a rounded rect
  541. -- @param integer tX
  542. -- @param integer tY
  543. -- @param integer tW
  544. -- @param integer tH
  545. -- @param integer tR
  546. -- @param string tStyle: (optional) "D" for draw (=default), "F" for fill, "DF" for both
  547. -- @param propList tLineGradProps: (optional)
  548. -- @param propList tFillGradProps: (optional)
  549. ----------------------------------------
  550. on mAddRoundedRect (me, tX, tY, tW, tH, tR, tStyle, tLineGradProps, tFillGradProps)
  551.   if voidP(tStyle) then tStyle="D"
  552.   mc = pCurrentPage.createEmptyMovieClip(me._getMcName(), pCurrentPage.getNextHighestDepth())
  553.  
  554.   if tStyle contains "D" then
  555.     me._setLineStyle(mc)
  556.     if listP(tLineGradProps) then
  557.       me._setGradientLineStyle(mc, tLineGradProps)
  558.     end if
  559.   end if
  560.  
  561.   if tStyle contains "F" then
  562.     if listP(tFillGradProps) then
  563.       me._setGradientFill(mc, tFillGradProps)
  564.     else
  565.       mc.beginFill(pFillColor, pFillAlpha)
  566.     end if
  567.   end if
  568.  
  569.   mc.moveTo(tX+tR, tY+0)
  570.   mc.lineTo(tX+tW - tR, tY+0)
  571.   mc.curveTo(tX+tW, tY+0, tX+tW, tY+tR)
  572.   mc.lineTo(tX+tW, tY+tR)
  573.   mc.lineTo(tX+tW, tY+tH - tR)
  574.   mc.curveTo(tX+tW, tY+tH, tX+tW - tR, tY+tH)
  575.   mc.lineTo(tX+tW - tR, tY+tH)
  576.   mc.lineTo(tX+tR, tY+tH)
  577.   mc.curveTo(tX+0, tY+tH, tX+0, tY+tH - tR)
  578.   mc.lineTo(tX+0, tY+tH - tR)
  579.   mc.lineTo(tX+0, tY+tR)
  580.   mc.curveTo(tX+0, tY+0,tX+tR, tY+0)
  581.   mc.lineTo(tX+tR, tY+0)
  582.  
  583.   if tStyle contains "F" then mc.endFill()
  584. end
  585.  
  586. ----------------------------------------
  587. -- Draws a circle or oval
  588. -- @param integer tX
  589. -- @param integer tY
  590. -- @param integer tRX
  591. -- @param integer tRY: (optional)
  592. -- @param string tStyle: (optional) "D" for draw (=default), "F" for fill, "DF" for both
  593. -- @param propList tLineGradProps: (optional)
  594. -- @param propList tFillGradProps: (optional)
  595. ----------------------------------------
  596. on mAddOval (me, tX, tY, tRX, tRY, tStyle, tLineGradProps, tFillGradProps)
  597.   if voidP(tStyle) then tStyle="D"
  598.   if voidP(tRY) then tRY=tRX
  599.  
  600.   mc = pCurrentPage.createEmptyMovieClip(me._getMcName(), pCurrentPage.getNextHighestDepth())
  601.  
  602.   if tStyle contains "D" then
  603.     me._setLineStyle(mc)
  604.     if listP(tLineGradProps) then
  605.       me._setGradientLineStyle(mc, tLineGradProps)
  606.     end if
  607.   end if
  608.  
  609.   if tStyle contains "F" then
  610.     if listP(tFillGradProps) then
  611.       me._setGradientFill(mc, tFillGradProps)
  612.     else
  613.       mc.beginFill(pFillColor, pFillAlpha)
  614.     end if
  615.   end if
  616.  
  617.   mc.moveTo(tX+tRX, tY)
  618.  
  619.   angleDelta = PI / 4  
  620.   xCtrlDist = tRX/cos(angleDelta/2)
  621.   yCtrlDist = tRY/cos(angleDelta/2)
  622.   a = 0
  623.   repeat with i = 1 to 8
  624.     a = a + angleDelta
  625.     cx = tX + cos(a-(angleDelta/2))*(xCtrlDist)
  626.     cy = tY + sin(a-(angleDelta/2))*(yCtrlDist)
  627.     ax = tX + cos(a)*tRX
  628.     ay = tY + sin(a)*tRY
  629.     mc.curveTo(cx, cy, ax, ay)
  630.   end repeat  
  631.   if tStyle contains "F" then mc.endFill()
  632. end
  633.  
  634. ----------------------------------------
  635. -- Draws a polygon
  636. -- @param list tPoints: List of points
  637. -- @param string tStyle: (optional) "D" for draw (=default), "F" for fill, "DF" for both
  638. -- @param propList tLineGradProps: (optional)
  639. -- @param propList tFillGradProps: (optional)
  640. ----------------------------------------
  641. on mAddPoly (me, tPoints, tStyle, tLineGradProps, tFillGradProps)
  642.   if voidP(tStyle) then tStyle="D"
  643.  
  644.   mc = pCurrentPage.createEmptyMovieClip(me._getMcName(), pCurrentPage.getNextHighestDepth())
  645.  
  646.   if tStyle contains "D" then
  647.     me._setLineStyle(mc)
  648.     if listP(tLineGradProps) then
  649.       me._setGradientLineStyle(mc, tLineGradProps)
  650.     end if
  651.   end if
  652.  
  653.   if tStyle contains "F" then
  654.     if listP(tFillGradProps) then
  655.       me._setGradientFill(mc, tFillGradProps)
  656.     else
  657.       mc.beginFill(pFillColor, pFillAlpha)
  658.     end if
  659.   end if
  660.  
  661.   cnt = count(tPoints)
  662.   p0 = tPoints[1]
  663.   mc.moveTo(p0[1], p0[2])
  664.   repeat with i = 2 to cnt
  665.     p = tPoints[i]
  666.     mc.lineTo(p[1], p[2])
  667.   end repeat
  668.   mc.lineTo(p0[1], p0[2])
  669.   if tStyle contains "F" then mc.endFill()
  670. end
  671.  
  672. ----------------------------------------
  673. -- Draws a quadratic bezier curve
  674. -- @param list tPoints: List of points, alternately a control and an anchor point
  675. -- @param string tStyle: (optional) "D" for draw (=default), "F" for fill, "DF" for both
  676. -- @param propList tLineGradProps: (optional)
  677. -- @param propList tFillGradProps: (optional)
  678. ----------------------------------------
  679. on mAddCurve (me, tPoints, tStyle, tLineGradProps, tFillGradProps)
  680.   if voidP(tStyle) then tStyle="D"
  681.  
  682.   mc = pCurrentPage.createEmptyMovieClip(me._getMcName(), pCurrentPage.getNextHighestDepth())
  683.  
  684.   if tStyle contains "D" then
  685.     me._setLineStyle(mc)
  686.     if listP(tLineGradProps) then
  687.       me._setGradientLineStyle(mc, tLineGradProps)
  688.     end if
  689.   end if
  690.  
  691.   if tStyle contains "F" then
  692.     if listP(tFillGradProps) then
  693.       me._setGradientFill(mc, tFillGradProps)
  694.     else
  695.       mc.beginFill(pFillColor, pFillAlpha)
  696.     end if
  697.   end if
  698.  
  699.   p0 = tPoints[1]
  700.   mc.moveTo(p0[1], p0[2])
  701.  
  702.   cnt = (count(tPoints)-1)/2
  703.   repeat with i = 1 to cnt
  704.     p1 = tPoints[2*i]
  705.     p2 = tPoints[2*i+1]
  706.     mc.curveTo(p1[1], p1[2],   p2[1], p2[2])
  707.   end repeat
  708.  
  709.   if tStyle contains "F" then mc.endFill()
  710. end
  711.  
  712. ----------------------------------------
  713. -- Explicitely sets the printMode for the specified page
  714. -- @param integer tPageNum
  715. -- @param integer tBool
  716. ----------------------------------------
  717. on mSetPagePrintAsBitmapMode (me, tPageNum, tBool)
  718.   if voidP(tBool) then tBool=1
  719.   if tBool then
  720.     if pPrintAsBitmap.getPos(tPageNum)=0 then
  721.       pPrintAsBitmap.add(tPageNum)
  722.     end if
  723.   else
  724.     pPrintAsBitmap.deleteOne(tPageNum)
  725.   end if
  726. end
  727.  
  728. ----------------------------------------
  729. -- Returns an image of the specified page (as 72 dpi)
  730. -- @param integer tPageNum: pageNumber as integer
  731. -- @param integer tAddBorder: (optional) if specified and true, a 1px black border will be drawn around the page image
  732. --
  733. -- @return image
  734. ----------------------------------------
  735. on mGetPreview (me, tPageNum, tAddBorder)
  736.  
  737.   mc = pFlashSprite["page"&tPageNum]
  738.  
  739.   bmp = pFlashSprite.newObject("flash.display.BitmapData", pPageFormat[1], pPageFormat[2]) --output_vid._width,output_vid._height);
  740.   --matrix = pFlashSprite.newObject("flash.geom.Matrix")
  741.  
  742.   bmp.draw(mc) --, matrix)
  743.   img = pFlashSprite.convert(#image, bmp)
  744.  
  745.   if (tAddBorder) then
  746.     img.draw(img.rect, [#shapeType:#rect, #lineSize:1, #color:RGB(0,0,0)])
  747.   end if
  748.  
  749.   bmp.dispose()
  750.  
  751.   return img
  752. end
  753.  
  754. ----------------------------------------
  755. -- Prints the current document
  756. -- @param integer tPrintAllPagesAsBitmap: (optional) if specified, forces to print all pages as bitmap, ignoring the previous settings
  757. --
  758. -- @return integer (1 or 0)
  759. ----------------------------------------
  760. on mPrint (me, tPrintAllPagesAsBitmap)
  761.   if pPageCnt=0 then return false
  762.   options = pFlashSprite.newObject("Object")
  763.  
  764.   myPrintJob = pFlashSprite.newObject("PrintJob")
  765.  
  766.  
  767.   ok = myPrintJob.start()
  768.   --> PrintJob.paperWidth
  769.   --> PrintJob.paperHeight
  770.   --> PrintJob.pageWidth
  771.   --> PrintJob.pageHeight
  772.   --> PrintJob.orientation
  773.  
  774.   if ok then
  775.     repeat with i = 1 to pPageCnt
  776.       options.printAsBitmap = tPrintAllPagesAsBitmap OR (pPrintAsBitmap.getPos(i)>0)
  777.       ok = myPrintJob.addPage("page"&i, pPrintArea, options, 1)
  778.     end repeat
  779.     ok = myPrintJob.send()
  780.   else
  781.     put "ERROR: PrintJob couldn't be started!"
  782.   end if
  783.  
  784.   -- delete myPrintJob
  785.   myPrintJob = VOID
  786.   return ok
  787. end
  788.  
  789. ----------------------------------------
  790. -- This method is used to render the page header. It is automatically called by mAddPage() and
  791. -- should not be called directly by the application. The implementation in the PRINT class is empty, so you have to
  792. -- subclass it and override the method if you want a specific processing.
  793. ----------------------------------------
  794. on mHeader me
  795.   nothing
  796. end
  797.  
  798. ----------------------------------------
  799. -- This method is used to render the page footer. It is automatically called by mAddPage() and
  800. -- should not be called directly by the application. The implementation in the PRINT class is empty, so you have to
  801. -- subclass it and override the method if you want a specific processing.
  802. ----------------------------------------
  803. on mFooter me
  804.   nothing
  805. end
  806.  
  807. --**************************************
  808. -- PRIVATE
  809. --**************************************
  810.  
  811. ----------------------------------------
  812. --
  813. ----------------------------------------
  814. on _getMcName (me)
  815.   pMcCnt = pMcCnt +1
  816.   return "mc"&pMcCnt
  817. end
  818.  
  819. ----------------------------------------
  820. --
  821. ----------------------------------------
  822. on _setLineStyle (me, mc)
  823.   mc.lineStyle(pLineStyle["thickness"],pLineStyle["rgb"],pLineStyle["alpha"],pLineStyle["pixelHinting"],pLineStyle["noScale"],pLineStyle["capsStyle"],pLineStyle["jointStyle"],pLineStyle["miterLimit"])
  824. end
  825.  
  826. ----------------------------------------
  827. --
  828. ----------------------------------------
  829. on _setGradientLineStyle (me, mc, props)
  830.  
  831.   if voidP(props["rotation"]) then props["rotation"]=0
  832.   if voidP(props["tx"]) then props["tx"]=0
  833.   if voidP(props["ty"]) then props["ty"]=0
  834.   if voidP(props["spreadMethod"]) then props["spreadMethod"]="pad"
  835.   if voidP(props["interpolationMethod"]) then props["interpolationMethod"]="RGB"
  836.   if voidP(props["focalPointRatio"]) then props["focalPointRatio"]=0
  837.  
  838.   fillType = props["fillType"]
  839.   colors = pFlashSprite.convert(#flashObjectArray, props["colors"])
  840.   alphas = pFlashSprite.convert(#flashObjectArray, props["alphas"])
  841.   ratios = pFlashSprite.convert(#flashObjectArray, props["ratios"])
  842.  
  843.   matrix = pFlashSprite.newObject("flash.geom.Matrix")
  844.  
  845.   -- public createGradientBox(width:Number, height:Number, [rotation:Number], [tx:Number], [ty:Number]) : Void
  846.   matrix.createGradientBox(props["width"], props["height"], props["rotation"], props["tx"], props["ty"])
  847.  
  848.   spreadMethod = props["spreadMethod"]
  849.   interpolationMethod = props["interpolationMethod"]
  850.   focalPointRatio = props["focalPointRatio"]
  851.  
  852.   mc.lineGradientStyle(fillType, colors, alphas, ratios, matrix, spreadMethod, interpolationMethod, focalPointRatio)
  853. end
  854.  
  855. ----------------------------------------
  856. --
  857. ----------------------------------------
  858. on _setGradientFill(me, mc, props)
  859.  
  860.   -- defaults
  861.   if voidP(props["rotation"]) then props["rotation"]=0
  862.   if voidP(props["tx"]) then props["tx"]=0
  863.   if voidP(props["ty"]) then props["ty"]=0
  864.   if voidP(props["spreadMethod"]) then props["spreadMethod"]="pad"
  865.   if voidP(props["interpolationMethod"]) then props["interpolationMethod"]="RGB"
  866.   if voidP(props["focalPointRatio"]) then props["focalPointRatio"]=0
  867.  
  868.   fillType = props["fillType"]
  869.   colors = pFlashSprite.convert(#flashObjectArray, props["colors"])
  870.   alphas = pFlashSprite.convert(#flashObjectArray, props["alphas"])
  871.   ratios = pFlashSprite.convert(#flashObjectArray, props["ratios"])
  872.  
  873.   matrix = pFlashSprite.newObject("flash.geom.Matrix")
  874.  
  875.   -- public createGradientBox(width:Number, height:Number, [rotation:Number], [tx:Number], [ty:Number]) : Void
  876.   matrix.createGradientBox(props["width"], props["height"], props["rotation"], props["tx"], props["ty"])
  877.  
  878.   spreadMethod = props["spreadMethod"]
  879.   interpolationMethod = props["interpolationMethod"]
  880.   focalPointRatio = props["focalPointRatio"]
  881.  
  882.   mc.beginGradientFill(fillType, colors, alphas, ratios, matrix, spreadMethod, interpolationMethod, focalPointRatio)
  883. end
  884.  
[raw code]