Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 

















User:Gringer/swfxml2svg

















User page
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
User contributions
User logs
View user groups
Upload file
Special pages
Permanent link
Page information
Get shortened URL
Download QR code
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 

< User:Gringer

#!/usr/bin/perl
use warnings;
use strict;

# swfxml2svg.pl -- extracts primitive shapes from SWFmill XML file
# Author: David Eccles (gringer) <programming@gringer.org>

#  -- Begin GPL license blurb --

# Copyright 2010 David Eccles (gringer)

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

#  -- End GPL license blurb --

# The most recent version of this code can be found at  
# http://en.wikipedia.org/wiki/User:Gringer/swfxml2svg


# The proper way to do this would be using XML parsers and SVG encoders 
# (e.g. see http://en.wikipedia.org/wiki/User:Gringer/perlshaper)

# All shapes are given a black stroke and red fill

my $oldX = 0;
my $oldY = 0;
my $oldShapeX = 0;
my $oldShapeY = 0;
my $continue = 0;
my $midPath = 0;

my $fontID = "";

my $doPrint = 0;

while(<>){
    if(/<swf/){
        print("<svg>\n");
        $doPrint = 1;
    }
    if(/DefineFont3 objectID="([0-9\-a-z]+)"/){
        $fontID = $1;
    }
    if(/Glyph map="([0-9\-a-z]+)"/){
        print(" <g id=\"font${fontID}glyph$1\">\n");
    }
    if(/\/Glyph>/){
        print(" </g>\n");
    }
    if(/ShapeSetup x="([0-9\-]+)" y="([0-9\-]+)"/){
        my $xpos = 0 + $1 / 20;
        my $ypos = 0 + $2 / 20;
        $oldX = $xpos;
        $oldY = $ypos;
        if($midPath){
            print("Z M$xpos,$ypos");
        } else {
            $oldShapeX = $xpos;
            $oldShapeY = $ypos;
            print("  <path stroke=\"black\" ".
                    "fill=\"red\" d=\"M$xpos,$ypos");
        }
        $midPath = 1;
    }
    if(/ShapeSetup\//){
        if($midPath){
            print("\" />\n");
        }
        $midPath = 0;
    }
    if(/LineTo x="([0-9\-]+)" y="([0-9\-]+)"/){
        my $xpos = $oldX + $1 / 20;
        my $ypos = $oldY + $2 / 20;
        $oldX = $xpos;
        $oldY = $ypos;
        print(" L$xpos,$ypos");
    }
    if(/CurveTo x1="([0-9\-]+)" y1="([0-9\-]+)" x2="([0-9\-]+)" y2="([0-9\-]+)"/){
        my $x1pos = $oldX + $1 / 20;
        my $y1pos = $oldY + $2 / 20;
        $oldX = $x1pos;
        $oldY = $y1pos;
        my $x2pos = $oldX + $3 / 20;
        my $y2pos = $oldY + $4 / 20;
        $oldX = $x2pos;
        $oldY = $y2pos;
        print(" Q$x1pos,$y1pos $x2pos,$y2pos");
    }
    if(/<\/swf/){
        print("</svg>\n");
    }
}

A text version of the GPL can be found here


Retrieved from "https://en.wikipedia.org/w/index.php?title=User:Gringer/swfxml2svg&oldid=1086822497"





This page was last edited on 8 May 2022, at 15:22 (UTC).

Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



Privacy policy

About Wikipedia

Disclaimers

Contact Wikipedia

Code of Conduct

Developers

Statistics

Cookie statement

Mobile view



Wikimedia Foundation
Powered by MediaWiki