Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Direct TTS (Text to speech)
cXtraPrinterDoc
Wheel Mouse
Generic behavior to change System Desktop Icons
Go to Different Movie
TaskXtra
Sound pan, rate shift
ColorCursor
Authoring Authorware
DriveInfo
 

 

 

Behavior Outline Text - Imaging Lingo

Added on 7/10/2006

 

Compatibilities:
behavior D8_5 D9 Mac PC Script Shockwave UK US

This item has not yet been rated

Author: Chunick (website)

creates an image of the text with a user specified outline and an optional dropshadow. Many parameters to set. Check comments in code for parameter descriptions.

-- Outline Text - Imaging Lingo
-- creates an image of the text with an
-- outline  from
-- the member passed or from the string
-- passed.
-- (c) 2006 by Josh Chunick
-- please keep comments intact,
-- otherwise use how you like

-- a big thank-you to Alex da Franca who
-- contributed a good deal to the optimizations
-- by setting up the use of the matrices and it's
-- parameter, useFastMatrix. The doTrimWhiteSpace
-- is now a boolean parameter (thanks to alex)
-- because of it's speed cost.

-- place this script in a moviescript

-- Parameters:
-- input - this can be a text member or a property list.
-- if you use a property list then the format looks like this:
-- [string,[:]] where the property list is a list of text formatting properties in this format:
-- eg. ["This is my outline text.", [#font: "Arial", #fontSize: 24, #fontStyle: [#bold], #alignment: #center, #charSpacing: 5]]
-- lnSize - integer. The size of the outline as an integer value.
-- knockout - boolean. Set to true to make the original text area transparent.
-- insideColor - colour object. colour of text. eg. rgb(255,0,0)
-- outsideColor - colour of outline and dropshadow. eg. color(0,255,0)
-- dsDirection - integer. four possible values corresponding to the direction of the shadow.
-- 1: top,left 2: top,right 3: bottom, right 4: bottom, left.
-- dsAmount - integer. The amount of offset of the dropshadow.
-- doTrimWhiteSpace -- boolean. Trims any whitespace that may be around the text. Default is 1. Speed cost.
-- useFastMatrix -- boolean. Uses fast or slow matrix for calculating outline. Default is 1. Speed cost.

on outlineText input, lnSize, knockout, insideColor, outsideColor, dsDirection, dsAmount, doTrimWhiteSpace, useFastMatrix
  ms = the milliseconds
  
  newMem = new(#text)
  newMem.boxType = #fixed
  newMem.topSpacing = 0
  newMem.leftIndent = 0
  Case input.ilk() of
    #member:
      newMem.media = input.media
    #list:
      newMem.wordWrap = False
      if input[2].getAProp(#font) <> VOID then
        newMem.font = input[2][#font]
      else
        newMem.font = "Arial"
      end if
      if input[2].getAProp(#fontSize) <> VOID then
        newMem.fontSize = input[2][#fontSize]
      else
        newMem.fontSize = 14
      end if
      if input[2].getAProp(#fontStyle) <> VOID then
        newMem.fontStyle = input[2][#fontStyle]
      else
        newMem.fontStyle = [#plain]
      end if
      if input[2].getAProp(#alignment) <> VOID then
        newMem.alignment = input[2][#alignment]
      else
        newMem.alignment = #left
      end if
      if input[2].getAProp(#fixedLineSpace) <> VOID then
        newMem.fixedLineSpace = input[2][#fixedLineSpace]
      end if
      if input[2].getAProp(#charSpacing) <> VOID then
        newMem.charSpacing = input[2][#charSpacing]
      end if
      if input[2].getAProp(#antiAlias) <> VOID then
        newMem.antiAlias = input[2][#antiAlias]
      end if
      if input[2].getAProp(#antiAliasThreshold) <> VOID then
        newMem.antiAliasThreshold = input[2][#antiAliasThreshold]
      else
        if newMem.fontSize <= 14 then
          newMem.antiAliasThreshold = 0
        end if
      end if
      if input[2].getAProp(#kerning) <> VOID then
        newMem.kerning = input[2][#kerning]
      end if
      if input[2].getAProp(#kerningThreshold) <> VOID then
        newMem.kerningThreshold = input[2][#kerningThreshold]
      else
        if newMem.fontSize <= 14 then
          newMem.kerningThreshold = 0
        end if
      end if
      
      newMem.text = input[1]
      lnCount = newMem.line.count
      newW = 0
      
      repeat with i = 1 to lnCount
        if newMem.charPosToLoc(newMem.line[1..i].char.count) > newW then
          newW = newMem.charPosToLoc(newMem.line[1..i].char.count + 1)[1]
        end if
      end repeat
      newMem.width = newW
  End Case
  
  newMem.width = newMem.width
  
  if voidP(lnSize) then lnSize = 1
  if voidP(knockout) then knockout = 0
  if voidP(insideColor) then insideColor = newMem.bgcolor
  if voidP(outsideColor) then outsideColor = newMem.color
  if voidP(dsDirection) then dsDirection = 0
  if voidP(dsAmount) then
    dsAmount = 1
    if voidP(dsDirection) then dsAmount = 0
  end if
  
  newMem.leftIndent = lnSize
  newMem.topSpacing = lnSize
  newMem.height = newMem.height + lnSize
  newMem.width = newMem.width + lnSize
  
  if Not(voidP(dsDirection)) then
    -- 1: top,left 2: top,right 3: bottom,right 4: bottom,left
    Case dsDirection of
      1:
        newMem.leftIndent = dsAmount + lnSize
        newMem.width = newMem.width + dsAmount + lnSize + 1
        newMem.topSpacing = dsAmount + lnSize
        newMem.height = newMem.height + lnSize
      2:
        newMem.rightIndent = dsAmount + lnSize
        newMem.width = newMem.width + dsAmount + lnSize + 1
        newMem.topSpacing = dsAmount + lnSize
        newMem.height = newMem.height + lnSize
      3:
        newMem.rightIndent = dsAmount + lnSize
        newMem.width = newMem.width + dsAmount + lnSize + 1
        newMem.height = newMem.height + dsAmount + lnSize
      4:
        newMem.leftIndent = dsAmount + lnSize
        newMem.width = newMem.width + dsAmount + lnSize + 1
        newMem.height = newMem.height + dsAmount + lnSize
    End Case
  end if
  
  aImg = newMem.image.extractAlpha()
  alphaImg = aImg.duplicate()
  
  newMemRect = newMem.image.rect
  if useFastMatrix or voidP(useFastMatrix) then
    n2 = lnSize - 1
    convMatrix = []
    repeat with x in [lnSize, -lnSize]
      repeat with y = -lnSize to lnSize
        convMatrix.add(point(x, y))
      end repeat
      repeat with y = n2 down to -n2
        convMatrix.add(point(y, x))
      end repeat
    end repeat
  else
    convMatrix = []
    repeat with n = -lnSize to lnSize
      repeat with m = -lnSize to lnSize
        convMatrix.add(point(n, m))
      end repeat
    end repeat
  end if
  
  cnt = convMatrix.count
  repeat with n = cnt down to 1  
    alphaImg.copyPixels(aImg, newMemRect.offset(convMatrix[n][1], convMatrix[n][2]), newMemRect, [#ink:39, #maskImage: aImg])
  end repeat
  
  newMemImage = image(newMemRect.width, newMemRect.height, 32, 0)
  newMemImage.fill(newMemRect, outsideColor)
  memImg = image(newMemRect.width, newMemRect.height, 32)
  
  repeat with n = count(convMatrix) down to 1
    memImg.copyPixels(newMemImage, newMemRect.offset(convMatrix[n][1], convMatrix[n][2]), newMemRect, [#maskImage: aImg])
  end repeat
  
  if Not(voidP(dsDirection)) then
    -- 1: top,left 2: top,right 3: bottom,right 4: bottom,left
    Case dsDirection of
      1:
        rectMod = rect(-dsAmount,-dsAmount,-dsAmount,-dsAmount)
      2:
        rectMod = rect(dsAmount,-dsAmount,dsAmount,-dsAmount)
      3:
        rectMod = rect(dsAmount,dsAmount,dsAmount,dsAmount)
      4:
        rectMod = rect(-dsAmount,dsAmount,-dsAmount,dsAmount)
    End Case
    alphaImg.copyPixels(alphaImg,(newMem.rect + rectMod), (newMem.rect),[#ink: 39, #maskImage: alphaImg])
    memImg.copyPixels(memImg,(newMem.rect + rectMod), (newMem.rect),[#ink: 39, #maskImage: alphaImg])
  end if
  
  if knockout then
    newMemImage.fill(newMemRect, rgb(255,255,255))
    alphaImg.copyPixels(newMemImage, newMemRect, newMemRect, [#maskImage: aImg])
  else
    newMemImage.fill(newMemRect, insideColor)
    memImg.copyPixels(newMemImage, newMemRect, newMemRect, [#maskImage: aImg])
  end if
  
  memImg.useAlpha = true
  memImg.setAlpha(alphaImg)
  
  if doTrimWhiteSpace or voidP(doTrimWhiteSpace) then memImg = memImg.trimWhiteSpace()
  
  newMem.erase()
  
  put the milliseconds - ms
  
  return memImg
  
end  

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail