Menu

Experiences making SWF generator webservice

2009-04-15
2013-04-17
  • Gies Bouwman

    Gies Bouwman - 2009-04-15

    Hi all,

    I thought I'd share some experiences developing a webservice based on swfdotnet that generates flash movies on-the-fly.

    Being the owner of the web site of a swimming club, I was looking for an easy way to generate a flash banner to display announcements. The users that need to modify its content - on a weekly basis - could not be expected to use complex flash studio software. However, I did want the flash banner to have some advanced features, like interactive tabpages, more-info link, photo backgrounds, etc. Moreover, it should have a uniform layout, irrespective of who had last been editting its content.

    I ended up developing an ASP.Net 2.0 webservice in Visual Studio 2005 using this swfdotnet library.

    The users can now log in on the (PHP powered) web site, edit the content using several webforms and upload new background images. Upon submitting the form, the content is packed into an XML request that is passed to a SOAP-method of the webservice, that is hosted on an external server. This method generates an SWF movie that is finally downloaded and copied to the proper directory.

    See the front page of http://www.hydrofiel.nl to view the result.
    Please leave me a message if you want to receive a copy of the code.

    Some final comments:
    - I found the support for texts (glyphs, http://www.half-serious.com/swf/format/definefont/index.html#fonts_and_text\) quite poor. I ended up extending the library on this point.
    - Several other bits of code had not been implemented yet either
    - I found ASV (http://www.buraks.com/asv/) an indispensible tool for debugging

    Cheers,
    Gies from the Netherlands

     
    • svdelle

      svdelle - 2009-04-15

      Hi Gies,

      Oh my, maybe you are my rescue. I've been struggling this swfdotnet library thing for some time now. As I can't seem to figure out the documentation at all.

      I'd really love a copy of your code if possible.

      I see hope up front. :)

      S

       
    • Gies Bouwman

      Gies Bouwman - 2009-04-16

      I'm new to sourceforge. I didn't manage to find an appropriate place to upload my code. I'm probably abusing the Tracker section of this group:

      https://sourceforge.net/tracker/?group_id=154817&atid=793321

      Good luck; let me know how you get on with it...

      Gies

       
  • Mahesh

    Mahesh - 2009-11-25

    Hi Gies,
    I need to add static text to an SWF file using SWFDotnet but having difficulties in creating Glyphs, can you provide the sample code used for achieving this.

    Thanks & Regards,
    Mahesh

     
  • Gies Bouwman

    Gies Bouwman - 2009-11-25

    Hi Mahesh,
    Did you open the link in message #3? Just follow the instructions there: it has a zip-file attached that contains a patch for the file GlyphShapesCollection.cs.
    Look for the method "GetGlyphShape" on this class (SwfDotNet.IO.Tags.Types.GlyphShapesCollection).
    Hope that helps.

     
  • Gies Bouwman

    Gies Bouwman - 2009-12-24

    *On Thu, 24 Dec 2009 06:41:54 +0100, Soni <preetisoni@users.sourceforge.net> wrote:

    Message body follows:

    HI Gies,
    I am using SWFDOTNET library for reading and manipulating swf file.I
    am stuck where I need to add static text to the swf file.

    There is TAg To add static text DefineTextTag resTag = new
    DefineTextTag();  in the documentation  but I am not getting how to use
    it.CAn you please help me out.

    I saw your patch GlyphShapesCollection.cs but not to understand
    it.Please hep me out.Can you provide a simple methond to add a static
    text using DefineTextTag(); if we can.

    Thanks in Advance

    Regards,
    Soni*

    hi Soni,

    Just follow the quickstart instructions that I have written. Once you have my flash banner working, run it in debug-mode, spend some time finding out how it works and make little modifications. Plenty of static texts there; I'm sure you'll understand it in the end.

    best,
    Gies

     
  • Brent Gardner

    Brent Gardner - 2010-01-10

    Here is my attempt at embedding fonts:

                Font font = new Font("Algerian", 500); // Algerian
                df = new DefineFont2Tag();
                df.CharacterId = swf.GetNewDefineId();
                df.FontName = "Algerian";
                foreach (char c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".ToCharArray()) //
                {
                    Console.WriteLine("char: " + c);
                    var col = new sdn.GlyphShapesCollection();
                    col.Add(font, c);
                    df.GlyphShapesTable.Add(c, col);
                }
                swf.Tags.Add(df);

    and my attempt at using them:

                // Define text
                var tag = new DefineText2Tag();
                tag.CharacterId = swf.GetNewDefineId();
                tag.Matrix.Rotate(45);
                //tag.Matrix.CopyFrom(tempMat);
                //tag.Matrix.MatrixData *= 20F;
                //tag.Matrix.MatrixData *= 20F;

                // Add a text record
                var tr = new sdn.TextRecord();
                tr.TextHeight = 1000;
                tr.TextColor = sdn.RGBColor.FromWinColor(Color.Black);
                tr.FontId = df.CharacterId;

                // Add a glyph
                tr.GlyphEntries.Add(new sdn.GlyphEntry(10, 0));
                //tr.GlyphEntries.Add(new sdn.GlyphEntry(1, 1));

                // Finish up
                tag.TextRecords.Add(tr);
                swf.Tags.Add(tag);
                swf.Tags.Add(new PlaceObject2Tag(tag.CharacterId, swf.Tags.Count, 1000, 2000));

    Unfortunately, it looks like every character is printing on top of the other. I think this has something to do with the glyphAdvance property. I'll keep banging away. If anyone else is farther than I am, I'd appreciate the help.

     
  • Gies Bouwman

    Gies Bouwman - 2010-01-11

    Just the other day Soni asked a similar question. You may find my answer useful too:

    1.how you  are calculating the width from "GetGlyphShape" function and
    logic behind the "GetGlyphShape" function.Can you please elaborate
    the fucntion of GetGlyphShape,how it works.

    In the GetGlyphShape function we are tracing the outline of a glyph/
    character point by point. The function has two local variables minX and
    maxX that are initialized at the extreme integer values. For each point of
    the character, we decide by the Min() and Max() functions if we have
    found a new value for the x-coordinate that is greater than the maxX that
    we have found so far. In a similar way we find the smallest x-coordinate
    value in minX. Just before leaving the function, we subtract the
    minimum from the maximum to obtain the width of the character.

    2.The logic behind the SetAdvanceIndex function.Why we need this and
    how we are using width for this.

    The SetAdvanceIndex function is needed because we're dealing with
    non-monospace fonts, which means that characters of a particular font
    collection may vary in width. In this function we populate look-up values
    for a single character C; this is used to determine where to position the
    next character after C in SWF-units (which is 1/20th of a pixel). We use
    the constants OFFSET and FACTOR as fixed and factorial values to
    determine how far subsequent characters are apart from eachother.
    You should play with these values to see their effect.

    If this doesn't help, you may proceed trying to get my original project going and simply replace the "Arial" font for "Algerian". A comparison should tell you why all your fonts are printed on the same location…

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.