Code Monkey home page Code Monkey logo

pluieelectrique-xfl2svg's Introduction

xfl2svg

Convert Adobe Animate XFL to SVG.

Install

You will need Python 3.7+ (tested on 3.9). Currently, installation requires building from source, so first install Flit with:

$ python3 -m pip install flit

Then, run either of:

$ pip install  .
$ pip install '.[tqdm]'   # If you want a progress bar

Usage

You will need an XFL project (tested with Animate 2022), either in compressed .fla form or as a decompressed directory. To convert all frames of "Scene 1" to SVG, run:

$ xfl2svg [path to .fla or dir] "Scene 1" [output dir]

You can change the frames rendered, SVG height and width, indent the SVG (Python 3.9+), etc. For example, this will render the first 5 frames of a symbol, centered in the viewport, with no background:

$ xfl2svg [path] "Symbol 1" [outdir] --last-frame 5 --center --no-background

Use xfl2svg -h to see all the options.

Limitations

This is a work in progress. Many XFL features are not supported (e.g. tweens, radial gradient) or do not work correctly. Use of these features may cause glitches in the output (e.g. stuttering, missing colors) or even crashes.

Other than that, the generated SVG should look similar to Animate's. It may not be identical, though, as Animate sometimes rounds coordinates by a few tenths of a pixel. It's not clear exactly why or when this is done, so it can't be replicated, but luckily, it's not very noticeable.

Finally, for convenience, xfl2svg makes no attempt to copy the structure of Animate's SVG. That is, the generated SVG has different whitespace, element IDs, element ordering, etc. compared to Animate. This should not affect the visual result.

How does it work?

There is no official documentation for XFL, so everything was discovered through experimentation and the few resources available:

This project has no documentation of XFL either, but the code hopefully serves as a substitute. In particular, shape/edge.py is densely commented and explains how shapes and strokes are converted from XFL to SVG.

For reference, here is an overview of the code:

  • __main__.py: Command-line interface
  • xfl_reader.py: Reads and preprocesses an XFL project. Provides timeline data to SvgRenderer.
  • svg_renderer.py: Recursively renders XFL to SVG. Uses shape for <DOMShape> and color_effect for effects on symbols.
  • shape/:
    • shape.py: Converts <DOMShape> to SVG. Uses edge for shapes/strokes and style for styles.
    • edge.py: Parses the XFL edge format and builds shapes/strokes.
    • style.py: Parses fill and stroke styles used by <DOMShape>.
    • gradient.py: Parses gradient fills.
  • color_effect.py: Parses color effects (e.g. brightness, tint, alpha) used on symbols.
  • util.py: Utility functions.

Also, XFL is closely related to Flash/SWF, so resources like the SWF file format specification and Ruffle's source code may be useful.

Legal

This program is licensed under the MIT License. See the LICENSE file for more information.

pluieelectrique-xfl2svg's People

Contributors

synthbot-anon avatar pluieelectrique avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.