swf2js 0.1.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -14
- package/package.json +11 -7
- package/studio/actionscript-roundtrip.test.js +54 -0
- package/studio/actionscript-scripts.test.js +169 -0
- package/studio/animated-image.test.js +137 -0
- package/studio/arithmetic.test.js +16 -0
- package/studio/as3-import.test.js +110 -0
- package/studio/audio-info.test.js +44 -0
- package/studio/components.test.js +152 -0
- package/studio/document-editing.test.js +92 -0
- package/studio/examples/01-space-mission.json +1628 -0
- package/studio/examples/02-clockwork-vault.json +1079 -0
- package/studio/examples/03-neon-synth.json +1364 -0
- package/studio/examples/04-kinetic-poster.json +923 -0
- package/studio/examples/05-signal-relay.json +1131 -0
- package/studio/examples/06-calculator.json +564 -0
- package/studio/frame-editing.test.js +129 -0
- package/studio/frame-events.test.js +117 -0
- package/studio/groups.test.js +88 -0
- package/studio/index.html +962 -0
- package/studio/interaction-triggers.test.js +37 -0
- package/studio/linked-actions.test.js +48 -0
- package/studio/lottie.test.js +208 -0
- package/studio/masks.test.js +43 -0
- package/studio/media-assets.test.js +62 -0
- package/studio/paint-tools.test.js +60 -0
- package/studio/playback.test.js +17 -0
- package/studio/project-io.test.js +405 -0
- package/studio/project-preview.test.js +475 -0
- package/studio/scene-transition.test.js +32 -0
- package/studio/server/archive-companions.js +27 -0
- package/studio/server/as3-library.js +91 -0
- package/studio/server/assets.js +162 -0
- package/studio/server/audio-info.js +82 -0
- package/studio/server/font-files.js +332 -0
- package/studio/server/http.js +135 -0
- package/studio/server/linked-actions.js +93 -0
- package/studio/server/png-decode.js +1 -0
- package/studio/server/project-movie.js +1164 -0
- package/studio/server/project-preview.js +152 -0
- package/studio/server/projects.js +370 -0
- package/studio/server/report.js +29 -0
- package/studio/server/routes.js +93 -0
- package/studio/server/swf-authoring.js +90 -0
- package/studio/server/swf-control-runtime.as +513 -0
- package/studio/server/swf-controls.js +119 -0
- package/studio/server/swf-export.js +293 -0
- package/studio/server/swf-import.js +1675 -0
- package/studio/server/swf-morphs.js +64 -0
- package/studio/server/swf-routes.js +42 -0
- package/studio/server/swf-streams.js +80 -0
- package/studio/server/swf-transition-runtime.as +52 -0
- package/studio/server/tween-recovery.js +106 -0
- package/studio/server-api.test.js +283 -0
- package/studio/server.js +320 -0
- package/studio/src/animated-image.js +423 -0
- package/studio/src/appearance-inspector.js +63 -0
- package/studio/src/arithmetic.js +50 -0
- package/studio/src/authored-controls.js +42 -0
- package/studio/src/busy.js +41 -0
- package/studio/src/canvas.js +430 -0
- package/studio/src/clipper-browser.js +2 -0
- package/studio/src/color-transform.js +38 -0
- package/studio/src/component-inspector.js +126 -0
- package/studio/src/components.js +268 -0
- package/studio/src/display-frame.js +262 -0
- package/studio/src/document-editing.js +69 -0
- package/studio/src/event-editor.js +150 -0
- package/studio/src/frame-editing.js +150 -0
- package/studio/src/frame-events.js +128 -0
- package/studio/src/frame-image.js +28 -0
- package/studio/src/groups.js +125 -0
- package/studio/src/handler-editor.js +122 -0
- package/studio/src/history.js +83 -0
- package/studio/src/imported-paths.js +99 -0
- package/studio/src/index.js +3582 -0
- package/studio/src/interaction-triggers.js +42 -0
- package/studio/src/json-patch.js +77 -0
- package/studio/src/layer-icons.js +25 -0
- package/studio/src/lottie-export.js +948 -0
- package/studio/src/lottie-import.js +1138 -0
- package/studio/src/masks.js +69 -0
- package/studio/src/media-assets.js +188 -0
- package/studio/src/media-library.js +193 -0
- package/studio/src/model.js +431 -0
- package/studio/src/numeric-fields.js +46 -0
- package/studio/src/object-list.js +57 -0
- package/studio/src/paint-tools.js +76 -0
- package/studio/src/placement-effects.js +74 -0
- package/studio/src/playback.js +10 -0
- package/studio/src/preview-audio.js +64 -0
- package/studio/src/preview-interactions.js +106 -0
- package/studio/src/preview-recorder.js +335 -0
- package/studio/src/preview-surface.js +338 -0
- package/studio/src/project-io.js +905 -0
- package/studio/src/project-session.js +375 -0
- package/studio/src/projects-dialog.js +319 -0
- package/studio/src/scene-transition.js +129 -0
- package/studio/src/script-editor.js +175 -0
- package/studio/src/script-references.js +74 -0
- package/studio/src/scripted-controls.js +146 -0
- package/studio/src/scripts.js +185 -0
- package/studio/src/stage-guides.js +101 -0
- package/studio/src/svg-animation.js +416 -0
- package/studio/src/svg-context.js +522 -0
- package/studio/src/svg-frame.js +413 -0
- package/studio/src/svg-import.js +1208 -0
- package/studio/src/swf-recording.js +104 -0
- package/studio/src/symbol-library.js +39 -0
- package/studio/src/symbols.js +62 -0
- package/studio/src/text-fields.js +58 -0
- package/studio/src/theme.js +43 -0
- package/studio/src/timeline.js +321 -0
- package/studio/src/vector-cut.js +103 -0
- package/studio/src/vector-geometry.js +254 -0
- package/studio/src/vector-style.js +146 -0
- package/studio/src/video-encode.js +84 -0
- package/studio/src/video-export.js +331 -0
- package/studio/src/video-mux.js +339 -0
- package/studio/src/video-playback.js +281 -0
- package/studio/src/workspace.js +344 -0
- package/studio/stroke-style.test.js +119 -0
- package/studio/styles.css +1547 -0
- package/studio/svg-export.test.js +162 -0
- package/studio/svg-import.test.js +318 -0
- package/studio/swf-authoring.test.js +140 -0
- package/studio/swf-export.test.js +324 -0
- package/studio/swf-import.test.js +489 -0
- package/studio/symbols.test.js +68 -0
- package/studio/tests/accessibility-interactions.mjs +138 -0
- package/studio/tests/appearance-interactions.mjs +103 -0
- package/studio/tests/control-interactions.mjs +60 -0
- package/studio/tests/event-interactions.mjs +117 -0
- package/studio/tests/external-resources.mjs +174 -0
- package/studio/tests/frame-image.mjs +71 -0
- package/studio/tests/html-export.mjs +68 -0
- package/studio/tests/import-files.mjs +131 -0
- package/studio/tests/lottie.mjs +125 -0
- package/studio/tests/mask-interactions.mjs +148 -0
- package/studio/tests/media-interactions.mjs +109 -0
- package/studio/tests/paint-interactions.mjs +64 -0
- package/studio/tests/project-interactions.mjs +244 -0
- package/studio/tests/script-interactions.mjs +178 -0
- package/studio/tests/scripted-control-interactions.mjs +107 -0
- package/studio/tests/svg-export.mjs +149 -0
- package/studio/tests/text-field-interactions.mjs +64 -0
- package/studio/tests/theme-interactions.mjs +53 -0
- package/studio/tests/timeline-browser.mjs +507 -0
- package/studio/tests/transition-interactions.mjs +94 -0
- package/studio/tests/trigger-interactions.mjs +93 -0
- package/studio/tests/video-export.mjs +243 -0
- package/studio/tests/workspace-interactions.mjs +226 -0
- package/studio/tween-recovery.test.js +31 -0
- package/studio/vector-style.test.js +56 -0
- package/studio/video-export.test.js +326 -0
- package/studiospec/actionscript.md +88 -0
- package/studiospec/architecture.md +378 -0
- package/studiospec/controls.md +100 -0
- package/studiospec/file-support.md +268 -0
- package/studiospec/lottie.md +69 -0
- package/studiospec/requirements.md +135 -0
- package/studiospec/stroke-style.md +95 -0
- package/studiospec/svg-export.md +83 -0
- package/studiospec/svg-import.md +139 -0
- package/studiospec/swooflib-integration.md +115 -0
- package/studiospec/tasks.md +573 -0
- package/studiospec/video-export.md +127 -0
- package/swf2js/__tests__/actionscript.test.js +1609 -0
- package/swf2js/__tests__/adpcm-audio.test.js +43 -0
- package/swf2js/__tests__/as2-compiler.test.js +153 -0
- package/swf2js/__tests__/as3-mixed-depth.test.js +498 -0
- package/swf2js/__tests__/authored-sprite-hit.test.js +118 -0
- package/swf2js/__tests__/authored-sprite-sizing.test.js +164 -0
- package/swf2js/__tests__/avm1-action-prefix.test.js +134 -0
- package/swf2js/__tests__/avm1-attach-movie.test.js +1151 -0
- package/swf2js/__tests__/avm1-boxhead-budget.test.js +73 -0
- package/swf2js/__tests__/avm1-cfg-bubble-tanks.test.js +101 -0
- package/swf2js/__tests__/avm1-cfg-mario-kart.test.js +184 -0
- package/swf2js/__tests__/avm1-cfg-mario.test.js +31 -0
- package/swf2js/__tests__/avm1-cfg-pacman.test.js +49 -0
- package/swf2js/__tests__/avm1-checkers-gameplay.test.js +122 -0
- package/swf2js/__tests__/avm1-clip-actions.test.js +2002 -0
- package/swf2js/__tests__/avm1-clone-drag.test.js +626 -0
- package/swf2js/__tests__/avm1-decompiler.test.js +102 -0
- package/swf2js/__tests__/avm1-dynamic-locals.test.js +159 -0
- package/swf2js/__tests__/avm1-formal-parameters.test.js +71 -0
- package/swf2js/__tests__/avm1-key-events.test.js +52 -0
- package/swf2js/__tests__/avm1-load-bitmap.test.js +75 -0
- package/swf2js/__tests__/avm1-loading-host-actions.test.js +764 -0
- package/swf2js/__tests__/avm1-multibyte-strings.test.js +63 -0
- package/swf2js/__tests__/avm1-pacman-gameplay.test.js +115 -0
- package/swf2js/__tests__/avm1-shape-hittest.test.js +311 -0
- package/swf2js/__tests__/avm1-shared-bodies.test.js +57 -0
- package/swf2js/__tests__/avm1-shared-runtime.test.js +1364 -0
- package/swf2js/__tests__/avm1-snake-gameplay.test.js +139 -0
- package/swf2js/__tests__/avm1-super.test.js +70 -0
- package/swf2js/__tests__/avm1-target-path.test.js +325 -0
- package/swf2js/__tests__/avm1-try.test.js +229 -0
- package/swf2js/__tests__/avm2-activation-closures.test.js +65 -0
- package/swf2js/__tests__/avm2-applytype.test.js +180 -0
- package/swf2js/__tests__/avm2-call-ops.test.js +232 -0
- package/swf2js/__tests__/avm2-callsuperid.test.js +231 -0
- package/swf2js/__tests__/avm2-class-initializer.test.js +219 -0
- package/swf2js/__tests__/avm2-custom-namespace.test.js +139 -0
- package/swf2js/__tests__/avm2-describe-type.test.js +96 -0
- package/swf2js/__tests__/avm2-dictionary.test.js +96 -0
- package/swf2js/__tests__/avm2-domain-memory.test.js +332 -0
- package/swf2js/__tests__/avm2-e4x.test.js +326 -0
- package/swf2js/__tests__/avm2-exceptions.test.js +81 -0
- package/swf2js/__tests__/avm2-findprop.test.js +110 -0
- package/swf2js/__tests__/avm2-getlex.test.js +166 -0
- package/swf2js/__tests__/avm2-global-slot.test.js +106 -0
- package/swf2js/__tests__/avm2-interface.test.js +95 -0
- package/swf2js/__tests__/avm2-multiname-precedence.test.js +148 -0
- package/swf2js/__tests__/avm2-named-namespace-types.test.js +106 -0
- package/swf2js/__tests__/avm2-optional-args.test.js +100 -0
- package/swf2js/__tests__/avm2-outer-scopes.test.js +101 -0
- package/swf2js/__tests__/avm2-package-internal-class.test.js +106 -0
- package/swf2js/__tests__/avm2-protected-namespace.test.js +105 -0
- package/swf2js/__tests__/avm2-protected.test.js +214 -0
- package/swf2js/__tests__/avm2-qwop-gameplay.test.js +116 -0
- package/swf2js/__tests__/avm2-runtime-namespaces.test.js +159 -0
- package/swf2js/__tests__/avm2-script-traits.test.js +89 -0
- package/swf2js/__tests__/avm2-shared-runtime.test.js +52 -0
- package/swf2js/__tests__/avm2-slot-ops.test.js +117 -0
- package/swf2js/__tests__/avm2-type-ops.test.js +224 -0
- package/swf2js/__tests__/bevel-filter.test.js +116 -0
- package/swf2js/__tests__/bitmap-button-mask.test.js +106 -0
- package/swf2js/__tests__/bitmap-data-draw.test.js +388 -0
- package/swf2js/__tests__/bitmap-decoder.test.js +108 -0
- package/swf2js/__tests__/bitmapdata-color-bounds.test.js +70 -0
- package/swf2js/__tests__/bitmapdata-copy-channel.test.js +91 -0
- package/swf2js/__tests__/bitmapdata-copy-pixels.test.js +136 -0
- package/swf2js/__tests__/bitmapdata-fill-compare.test.js +241 -0
- package/swf2js/__tests__/bitmapdata-filter.test.js +232 -0
- package/swf2js/__tests__/bitmapdata-hit-test.test.js +71 -0
- package/swf2js/__tests__/bitmapdata-merge.test.js +84 -0
- package/swf2js/__tests__/bitmapdata-palette-map.test.js +92 -0
- package/swf2js/__tests__/bitmapdata-pixels-io.test.js +198 -0
- package/swf2js/__tests__/bitmapdata-threshold.test.js +97 -0
- package/swf2js/__tests__/bitmapdata-vector.test.js +82 -0
- package/swf2js/__tests__/blur-filter.test.js +48 -0
- package/swf2js/__tests__/bundle-emitter.test.js +394 -0
- package/swf2js/__tests__/button-actions.test.js +370 -0
- package/swf2js/__tests__/button-color-transform.test.js +48 -0
- package/swf2js/__tests__/button-decoder.test.js +106 -0
- package/swf2js/__tests__/button-hit-test.test.js +825 -0
- package/swf2js/__tests__/button-scaling-grid.test.js +124 -0
- package/swf2js/__tests__/button-sound.test.js +105 -0
- package/swf2js/__tests__/bytearray-coercion.test.js +23 -0
- package/swf2js/__tests__/bytearray-object-serialization.test.js +380 -0
- package/swf2js/__tests__/cfg-switch-loop.test.js +103 -0
- package/swf2js/__tests__/clip-depth-mask.test.js +119 -0
- package/swf2js/__tests__/clipped-bitmap-fill.test.js +118 -0
- package/swf2js/__tests__/companion-swf.test.js +638 -0
- package/swf2js/__tests__/context-menu.test.js +149 -0
- package/swf2js/__tests__/convolution-filter.test.js +74 -0
- package/swf2js/__tests__/definefont4.test.js +280 -0
- package/swf2js/__tests__/display-displacement.test.js +161 -0
- package/swf2js/__tests__/display-list.test.js +80 -0
- package/swf2js/__tests__/display-mask-render.test.js +656 -0
- package/swf2js/__tests__/displayobject-stage.test.js +320 -0
- package/swf2js/__tests__/embedded-script-audio.test.js +131 -0
- package/swf2js/__tests__/embedded-swf.test.js +202 -0
- package/swf2js/__tests__/embedded-textfield.test.js +107 -0
- package/swf2js/__tests__/embedded-timeline-audio.test.js +182 -0
- package/swf2js/__tests__/embedded-timeline-input.test.js +420 -0
- package/swf2js/__tests__/embedded-timer-lifecycle.test.js +145 -0
- package/swf2js/__tests__/event-priority-order.test.js +125 -0
- package/swf2js/__tests__/event-weak-listeners.test.js +53 -0
- package/swf2js/__tests__/event-will-trigger.test.js +43 -0
- package/swf2js/__tests__/flash-text-engine-content.test.js +115 -0
- package/swf2js/__tests__/flash-text-engine-format.test.js +95 -0
- package/swf2js/__tests__/flash-text-engine-line.test.js +314 -0
- package/swf2js/__tests__/font-encoder.test.js +95 -0
- package/swf2js/__tests__/font-outline-text.test.js +659 -0
- package/swf2js/__tests__/glow-shadow-filter.test.js +68 -0
- package/swf2js/__tests__/graphics-bitmap-smoothing.test.js +32 -0
- package/swf2js/__tests__/graphics-fill-lifetime.test.js +36 -0
- package/swf2js/__tests__/graphics-gradient-matrix.test.js +53 -0
- package/swf2js/__tests__/graphics-stroke-hit-test.test.js +457 -0
- package/swf2js/__tests__/hit-test-primitives.test.js +414 -0
- package/swf2js/__tests__/input-events.test.js +714 -0
- package/swf2js/__tests__/integration/corpus.test.js +41 -0
- package/swf2js/__tests__/loader-embedded-swf.test.js +210 -0
- package/swf2js/__tests__/loader-info.test.js +81 -0
- package/swf2js/__tests__/local-connection.test.js +122 -0
- package/swf2js/__tests__/morph-focal-gradient.test.js +51 -0
- package/swf2js/__tests__/morph-topology.test.js +267 -0
- package/swf2js/__tests__/movie-data-codec.test.js +128 -0
- package/swf2js/__tests__/nellymoser-audio.test.js +84 -0
- package/swf2js/__tests__/opaque-background-cache.test.js +352 -0
- package/swf2js/__tests__/path-stream.test.js +81 -0
- package/swf2js/__tests__/place-object-filters.test.js +88 -0
- package/swf2js/__tests__/place-object3-decoder.test.js +116 -0
- package/swf2js/__tests__/place-object3-image.test.js +85 -0
- package/swf2js/__tests__/player-version.test.js +46 -0
- package/swf2js/__tests__/root-textfield.test.js +287 -0
- package/swf2js/__tests__/scaling-grid.test.js +183 -0
- package/swf2js/__tests__/shape-decoder.test.js +361 -0
- package/swf2js/__tests__/shape-line-style2.test.js +138 -0
- package/swf2js/__tests__/shape-nonscaling-stroke.test.js +131 -0
- package/swf2js/__tests__/shape-pixel-hint.test.js +101 -0
- package/swf2js/__tests__/simplebutton-pointer.test.js +1477 -0
- package/swf2js/__tests__/socket-offline.test.js +67 -0
- package/swf2js/__tests__/sound-avm1-stop.test.js +99 -0
- package/swf2js/__tests__/sound-envelope.test.js +110 -0
- package/swf2js/__tests__/sound-extract.test.js +168 -0
- package/swf2js/__tests__/sound-id3.test.js +283 -0
- package/swf2js/__tests__/sound-load.test.js +259 -0
- package/swf2js/__tests__/sound-mixer-spectrum.test.js +261 -0
- package/swf2js/__tests__/sound-stream-sprite.test.js +624 -0
- package/swf2js/__tests__/sound-transform.test.js +104 -0
- package/swf2js/__tests__/speex-audio.test.js +77 -0
- package/swf2js/__tests__/stage-noscale.test.js +45 -0
- package/swf2js/__tests__/swf-encoder.test.js +134 -0
- package/swf2js/__tests__/swflib-assemble.test.js +20 -0
- package/swf2js/__tests__/textfield-html-text.test.js +368 -0
- package/swf2js/__tests__/textfield-line-layout.test.js +339 -0
- package/swf2js/__tests__/textfield-programmatic-overlay.test.js +2506 -0
- package/swf2js/__tests__/textfield-scroll.test.js +79 -0
- package/swf2js/__tests__/textfield-selection.test.js +383 -0
- package/swf2js/__tests__/timeline-effect-surfaces.test.js +295 -0
- package/swf2js/__tests__/timeline-named-anchor.test.js +139 -0
- package/swf2js/__tests__/timeline-scenes.test.js +1723 -0
- package/swf2js/__tests__/urlloader-http-status.test.js +236 -0
- package/{src → swf2js}/cli.js +43 -11
- package/swf2js/compiler/as2-classes.js +156 -0
- package/swf2js/compiler/as2-parser.js +598 -0
- package/swf2js/compiler/avm1-codegen.js +897 -0
- package/swf2js/compiler/index.js +28 -0
- package/{src → swf2js}/decoder/button-decoder.js +3 -1
- package/swf2js/decoder/png.js +114 -0
- package/{src → swf2js}/decoder/shape-decoder.js +20 -10
- package/{src → swf2js}/decoder/tag-decoder.js +5 -3
- package/{src → swf2js}/decoder/tag-types.js +4 -0
- package/swf2js/decompiler/avm1-decompiler.js +1138 -0
- package/{src → swf2js}/emitter/asset-encoder.js +66 -113
- package/{src → swf2js}/emitter/bundle-emitter.js +209 -78
- package/swf2js/emitter/external-resources.js +39 -0
- package/swf2js/emitter/movie-data-codec.js +91 -0
- package/swf2js/encoder/bit-writer.js +182 -0
- package/swf2js/encoder/shape-encoder.js +310 -0
- package/swf2js/encoder/swf-builder.js +639 -0
- package/swf2js/encoder/swf-writer.js +55 -0
- package/{src/runtime/swflib/assemble.js → swf2js/runtime/assemble-swooflib.js} +4 -3
- package/{src → swf2js}/runtime/avm1-runtime.js +102 -63
- package/{src → swf2js}/runtime/index.js +1 -1
- package/{src → swf2js}/runtime/movie-runtime.js +28 -2
- package/{src → swf2js}/transpiler/actionscript.js +82 -19
- package/{src → swf2js}/transpiler/avm1/avm1-opcodes.js +5 -3
- package/{src → swf2js}/transpiler/avm1/avm1-transpiler.js +69 -6
- package/{src → swf2js}/transpiler/avm2/avm2-transpiler.js +1 -1
- package/{src → swf2js}/transpiler/timeline/display-list.js +41 -22
- package/{src → swf2js}/transpiler/timeline/timeline-codegen.js +97 -36
- package/swooflib/README.md +569 -0
- package/swooflib/adpcm.js +147 -0
- package/{src/runtime/swflib → swooflib}/builtins.js +6 -0
- package/{src/runtime/swflib → swooflib}/context-menu.js +7 -1
- package/swooflib/control-definitions.js +42 -0
- package/swooflib/control-widget.js +763 -0
- package/swooflib/controls.js +300 -0
- package/{src/runtime/swflib → swooflib}/display.js +16 -10
- package/{src/runtime/swflib → swooflib}/events.js +11 -0
- package/{src/runtime/swflib → swooflib}/flash.js +6 -5
- package/{src/runtime/swflib → swooflib}/graphics.js +81 -19
- package/{src/runtime/swflib → swooflib}/input.js +12 -14
- package/{src/runtime/swflib → swooflib}/loader.js +52 -22
- package/swooflib/movie-network.js +86 -0
- package/swooflib/path-stream.js +169 -0
- package/{src/runtime/swflib → swooflib}/render.js +3 -13
- package/{src/runtime/swflib → swooflib}/sound.js +25 -2
- package/{src/runtime/swflib → swooflib}/stage.js +3 -3
- package/swooflib/stream-time.js +21 -0
- package/{src/runtime/swflib → swooflib}/system.js +88 -37
- package/{src/runtime/swflib → swooflib}/text-paint.js +14 -3
- package/{src/runtime/swflib → swooflib}/text.js +8 -0
- package/swooflib/xml-node.js +53 -0
- package/src/emitter/timeline-data-codec.js +0 -58
- /package/{src → swf2js}/decoder/symbol-table.js +0 -0
- /package/{src → swf2js}/emitter/embedded-swf.js +0 -0
- /package/{src → swf2js}/emitter/font-encoder.js +0 -0
- /package/{src → swf2js}/model/swf-document.js +0 -0
- /package/{src → swf2js}/model/transpile-result.js +0 -0
- /package/{src → swf2js}/parser/bit-reader.js +0 -0
- /package/{src → swf2js}/parser/decompressor.js +0 -0
- /package/{src → swf2js}/parser/swf-parser.js +0 -0
- /package/{src → swf2js}/pretty-printer/pretty-printer.js +0 -0
- /package/{src → swf2js}/runtime/avm2-runtime.js +0 -0
- /package/{src → swf2js}/runtime/embedded-movie-runtime.js +0 -0
- /package/{src → swf2js}/transpiler/avm1/avm1-ir.js +0 -0
- /package/{src → swf2js}/transpiler/avm1/avm1-rewrite.js +0 -0
- /package/{src → swf2js}/transpiler/avm2/abc-reader.js +0 -0
- /package/{src → swf2js}/transpiler/cfg-structurer.js +0 -0
- /package/{src → swf2js}/util/diagnostics.js +0 -0
- /package/{src → swf2js}/util/logger.js +0 -0
- /package/{src/runtime/swflib → swooflib}/bitmap-image.js +0 -0
- /package/{src/runtime/swflib → swooflib}/bitmap.js +0 -0
- /package/{src/runtime/swflib → swooflib}/bytearray.js +0 -0
- /package/{src/runtime/swflib → swooflib}/compiled-swf.js +0 -0
- /package/{src/runtime/swflib → swooflib}/cursor-flag.js +0 -0
- /package/{src/runtime/swflib → swooflib}/dictionary.js +0 -0
- /package/{src/runtime/swflib → swooflib}/filters.js +0 -0
- /package/{src/runtime/swflib → swooflib}/geom.js +0 -0
- /package/{src/runtime/swflib → swooflib}/glyph-metrics.js +0 -0
- /package/{src/runtime/swflib → swooflib}/host.js +0 -0
- /package/{src/runtime/swflib → swooflib}/inherit.js +0 -0
- /package/{src/runtime/swflib → swooflib}/marks.js +0 -0
- /package/{src/runtime/swflib → swooflib}/matrix3d.js +0 -0
- /package/{src/runtime/swflib → swooflib}/pointer-bridge.js +0 -0
- /package/{src/runtime/swflib → swooflib}/projection.js +0 -0
- /package/{src/runtime/swflib → swooflib}/sprite-drag.js +0 -0
- /package/{src/runtime/swflib → swooflib}/stage-ref.js +0 -0
- /package/{src/runtime/swflib → swooflib}/text-field.js +0 -0
- /package/{src/runtime/swflib → swooflib}/transform.js +0 -0
- /package/{src/runtime/swflib → swooflib}/xml.js +0 -0
|
@@ -0,0 +1,659 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { readFileSync } from 'fs';
|
|
3
|
+
import { runInNewContext } from 'node:vm';
|
|
4
|
+
import * as acorn from 'acorn';
|
|
5
|
+
import { parse } from '../parser/swf-parser.js';
|
|
6
|
+
import { decode } from '../decoder/tag-decoder.js';
|
|
7
|
+
import { TAG } from '../decoder/tag-types.js';
|
|
8
|
+
import { SymbolTable } from '../decoder/symbol-table.js';
|
|
9
|
+
import { decodeGlyphShape } from '../decoder/shape-decoder.js';
|
|
10
|
+
import { encodeBrowserFont } from '../emitter/font-encoder.js';
|
|
11
|
+
import { transpileActionScript } from '../transpiler/actionscript.js';
|
|
12
|
+
import { buildDisplayList } from '../transpiler/timeline/display-list.js';
|
|
13
|
+
import { generateTimelineEngine, serializeTimelineData, timelineHelpersSource } from '../transpiler/timeline/timeline-codegen.js';
|
|
14
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
15
|
+
import { DiagnosticsCollector } from '../util/diagnostics.js';
|
|
16
|
+
|
|
17
|
+
const corpus = ['archive/Swf/bubble-tanks-2.swf', 'archive/Swf/age-of-war.swf', 'archive/Swf/plazma-burst-2.swf'];
|
|
18
|
+
|
|
19
|
+
function packBits(bits) {
|
|
20
|
+
const bytes = [];
|
|
21
|
+
for (let i = 0; i < bits.length; i += 8) bytes.push(parseInt(bits.slice(i, i + 8).padEnd(8, '0'), 2));
|
|
22
|
+
return bytes;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function tinyGlyph() {
|
|
26
|
+
const edges = ['11000010100', '11000011101', '11000010011'];
|
|
27
|
+
return new Uint8Array([0x10, ...packBits('000011' + '0000100' + '1' + edges.join('') + '000000')]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe('embedded font outline text', () => {
|
|
31
|
+
it('paints the UTF-8 block character from the original Plazma Burst 2 status field', async () => {
|
|
32
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/plazma-burst-2.swf'));
|
|
33
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
34
|
+
const id = 1198;
|
|
35
|
+
const label = '_subj.Main█';
|
|
36
|
+
const edit = symbolTable.get(id);
|
|
37
|
+
expect(edit.initialText).toContain(label);
|
|
38
|
+
const font = symbolTable.get(edit.fontId);
|
|
39
|
+
expect(font.codes).toContain(0x2588);
|
|
40
|
+
|
|
41
|
+
const selected = new SymbolTable();
|
|
42
|
+
selected.set(id, edit);
|
|
43
|
+
selected.set(edit.fontId, font);
|
|
44
|
+
const engine = generateTimelineEngine(buildDisplayList([], selected), {});
|
|
45
|
+
const draw = runInNewContext(`${SWFLIB_SOURCE}\n${engine}\ndrawCharacter;`, {
|
|
46
|
+
Path2D: class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} },
|
|
47
|
+
});
|
|
48
|
+
let outlines = 0;
|
|
49
|
+
const deviceText = [];
|
|
50
|
+
const ctx = {
|
|
51
|
+
globalAlpha: 1, save() {}, restore() {}, setTransform() {}, translate() {}, scale() {},
|
|
52
|
+
beginPath() {}, rect() {}, clip() {},
|
|
53
|
+
fill() { outlines++; },
|
|
54
|
+
fillText(text) { deviceText.push(text); },
|
|
55
|
+
};
|
|
56
|
+
draw(ctx, id, { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 }, 0);
|
|
57
|
+
expect(outlines).toBe(label.length);
|
|
58
|
+
expect(deviceText).toEqual([]);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it.each([[5, [0xe9]], [6, [0xc3, 0xa9]]])('decodes initial authored text according to SWF %i', (version, bytes) => {
|
|
62
|
+
const { symbolTable } = decode({ header: { version }, tags: [
|
|
63
|
+
// Character ID, empty bounds, HasText, empty variable name, then the terminated initial text.
|
|
64
|
+
{ code: TAG.DefineEditText, data: Uint8Array.of(1, 0, 0, 0x80, 0, 0, ...bytes, 0) },
|
|
65
|
+
] });
|
|
66
|
+
expect(symbolTable.get(1).initialText).toBe('é');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('preserves UTF-8 font names from Grow Tower through its text field and packaged font', async () => {
|
|
70
|
+
const { doc } = await parse(readFileSync('archive/Swf/grow-tower.swf'));
|
|
71
|
+
const { tags, symbolTable } = decode(doc);
|
|
72
|
+
const { characters } = buildDisplayList(tags, symbolTable);
|
|
73
|
+
const japanese = 'ヒラギノ角ゴ8等幅';
|
|
74
|
+
|
|
75
|
+
expect(symbolTable.get(53).name).toBe(japanese);
|
|
76
|
+
expect(characters[54].font).toBe(japanese);
|
|
77
|
+
expect(encodeBrowserFont(symbolTable.get(53)).includes(Buffer.from(japanese, 'utf16le').swap16())).toBe(true);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('retains the authored Age of War full name and copyright in its TrueType font', async () => {
|
|
81
|
+
const { doc } = await parse(readFileSync('archive/Swf/age-of-war.swf'));
|
|
82
|
+
const { symbolTable } = decode(doc);
|
|
83
|
+
const font = symbolTable.get(197);
|
|
84
|
+
expect(font).toMatchObject({ name: 'Arial_12pt_st', fullName: 'Arial Bold', copyright: expect.stringContaining('©') });
|
|
85
|
+
const packaged = encodeBrowserFont(font);
|
|
86
|
+
for (const value of [font.name, font.fullName, font.copyright]) {
|
|
87
|
+
expect(packaged.includes(Buffer.from(value, 'utf16le').swap16())).toBe(true);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it.each([
|
|
92
|
+
[6, TAG.DefineFontInfo, [0xc3, 0xa9], 0x01, 'é'],
|
|
93
|
+
[6, TAG.DefineFontInfo2, [0xe6, 0x98, 0x8e], 0x01, '明'],
|
|
94
|
+
[5, TAG.DefineFontInfo, [0x83, 0x65, 0x83, 0x58, 0x83, 0x67], 0x11, 'テスト'],
|
|
95
|
+
[5, TAG.DefineFontInfo, [0x80], 0x09, '€'],
|
|
96
|
+
])('decodes SWF %i supplementary font names with the authored encoding', (version, code, name, flags, expected) => {
|
|
97
|
+
const language = code === TAG.DefineFontInfo2 ? [2] : [];
|
|
98
|
+
const { symbolTable } = decode({ header: { version }, tags: [
|
|
99
|
+
{ code: TAG.DefineFont, data: Uint8Array.of(1, 0, 2, 0, ...tinyGlyph()) },
|
|
100
|
+
{ code, data: Uint8Array.of(1, 0, name.length, ...name, flags, ...language, 65, 0) },
|
|
101
|
+
] });
|
|
102
|
+
|
|
103
|
+
expect(symbolTable.get(1)).toMatchObject({ name: expected, codes: [65] });
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('associates Font3 alignment zones with their glyphs in source order', () => {
|
|
107
|
+
const glyph = tinyGlyph();
|
|
108
|
+
const offsets = [6, 6 + glyph.length, 6 + 2 * glyph.length].flatMap(offset => [offset, 0]);
|
|
109
|
+
const font = { code: TAG.DefineFont3, data: Uint8Array.of(1, 0, 4, 0, 0, 2, 0, ...offsets, ...glyph, ...glyph, 65, 0, 66, 0) };
|
|
110
|
+
const zoneHeader = [1, 0, 0x80];
|
|
111
|
+
const firstGlyph = [2, 0, 0x40, 0, 0x3c, 0, 0xc1, 0, 2, 0x03];
|
|
112
|
+
const secondGlyph = [2, 0, 0, 0, 0, 0, 0x80, 0, 0, 0x02];
|
|
113
|
+
const zones = { code: TAG.DefineFontAlignZones, data: Uint8Array.of(...zoneHeader, ...firstGlyph, ...secondGlyph) };
|
|
114
|
+
const diagnostics = new DiagnosticsCollector();
|
|
115
|
+
const { tags, symbolTable } = decode({ tags: [zones, font] }, diagnostics);
|
|
116
|
+
const alignment = symbolTable.get(1).alignmentZones;
|
|
117
|
+
expect(alignment).toBe(tags[0].alignmentZones);
|
|
118
|
+
expect(alignment).toEqual({ csmTableHint: 2, records: [
|
|
119
|
+
{ data: [{ coordinate: 1, range: 0.5 }, { coordinate: -1.25, range: 2 ** -16 }], maskX: true, maskY: true },
|
|
120
|
+
{ data: [{ coordinate: 0, range: 0 }, { coordinate: -0, range: 0 }], maskX: false, maskY: true },
|
|
121
|
+
] });
|
|
122
|
+
expect(buildDisplayList(tags, symbolTable).characters[1].alignmentZones).toBeUndefined();
|
|
123
|
+
expect(diagnostics.all()).toEqual([]);
|
|
124
|
+
|
|
125
|
+
for (const [badZoneData, message] of [
|
|
126
|
+
[[...zoneHeader, ...firstGlyph.slice(0, -1)], 'Invalid DefineFontAlignZones record'],
|
|
127
|
+
[[...zoneHeader, ...firstGlyph], 'record count does not match'],
|
|
128
|
+
]) {
|
|
129
|
+
const badDiagnostics = new DiagnosticsCollector();
|
|
130
|
+
const { symbolTable: badSymbols } = decode({ tags: [font, { ...zones, data: Uint8Array.from(badZoneData) }] }, badDiagnostics);
|
|
131
|
+
expect(badSymbols.get(1).alignmentZones).toBeUndefined();
|
|
132
|
+
expect(badDiagnostics.errors()).toHaveLength(0);
|
|
133
|
+
expect(badDiagnostics.warnings()[0].message).toContain(message);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('links CSM rendering settings to both static-text tags and EditText', () => {
|
|
138
|
+
function settings(id, mode, fit, thickness, sharpness) {
|
|
139
|
+
const data = new Uint8Array(12);
|
|
140
|
+
const view = new DataView(data.buffer);
|
|
141
|
+
view.setUint16(0, id, true);
|
|
142
|
+
view.setUint8(2, (mode << 6) | (fit << 3));
|
|
143
|
+
view.setFloat32(3, thickness, true);
|
|
144
|
+
view.setFloat32(7, sharpness, true);
|
|
145
|
+
return { code: TAG.CSMTextSettings, data };
|
|
146
|
+
}
|
|
147
|
+
const truncated = settings(3, 1, 0, 2, 2).data.subarray(0, 11);
|
|
148
|
+
const diagnostics = new DiagnosticsCollector();
|
|
149
|
+
const { tags, symbolTable } = decode({ tags: [
|
|
150
|
+
{ code: TAG.DefineText, data: Uint8Array.of(1, 0, 0, 0, 0, 0, 0) },
|
|
151
|
+
settings(1, 1, 2, 0.75, -0.25),
|
|
152
|
+
{ code: TAG.DefineText2, data: Uint8Array.of(2, 0, 0, 0, 0, 0, 0) },
|
|
153
|
+
settings(2, 0, 0, 0, 0),
|
|
154
|
+
{ code: TAG.DefineEditText, data: Uint8Array.of(3, 0, 0, 0, 0, 0) },
|
|
155
|
+
settings(3, 1, 1, -0.5, 0.125),
|
|
156
|
+
{ code: TAG.CSMTextSettings, data: truncated },
|
|
157
|
+
settings(3, 1, 2, NaN, 0),
|
|
158
|
+
] }, diagnostics);
|
|
159
|
+
const entries = [tags[1], tags[3], tags[5]];
|
|
160
|
+
expect(entries.map(tag => [tag.type, tag.textId, tag.csmTextSettings])).toEqual([
|
|
161
|
+
['CSMTextSettings', 1, { useFlashType: 1, gridFit: 2, thickness: 0.75, sharpness: -0.25 }],
|
|
162
|
+
['CSMTextSettings', 2, { useFlashType: 0, gridFit: 0, thickness: 0, sharpness: 0 }],
|
|
163
|
+
['CSMTextSettings', 3, { useFlashType: 1, gridFit: 1, thickness: -0.5, sharpness: 0.125 }],
|
|
164
|
+
]);
|
|
165
|
+
const displayList = buildDisplayList(tags, symbolTable);
|
|
166
|
+
const serialized = JSON.parse(serializeTimelineData(displayList, {}).characters);
|
|
167
|
+
for (const { textId, csmTextSettings } of entries) {
|
|
168
|
+
expect(symbolTable.get(textId).csmTextSettings).toBe(csmTextSettings);
|
|
169
|
+
expect(displayList.characters[textId].csmTextSettings).toBe(csmTextSettings);
|
|
170
|
+
expect(serialized[textId].csmTextSettings).toEqual(csmTextSettings);
|
|
171
|
+
}
|
|
172
|
+
expect(diagnostics.errors()).toEqual([]);
|
|
173
|
+
expect(diagnostics.warnings().map(warning => warning.message)).toEqual([
|
|
174
|
+
'Truncated CSMTextSettings record', 'Invalid CSMTextSettings thickness or sharpness',
|
|
175
|
+
]);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('decodes a DefineFont v1 glyph outline and its supplementary character mapping', () => {
|
|
179
|
+
const glyph = tinyGlyph();
|
|
180
|
+
const fontData = new Uint8Array([1, 0, 2, 0, ...glyph]);
|
|
181
|
+
const fontInfoData = new Uint8Array([1, 0, 4, 84, 101, 115, 116, 1, 65, 0]);
|
|
182
|
+
const { symbolTable } = decode({ tags: [
|
|
183
|
+
{ code: TAG.DefineFont, offset: 0, data: fontData },
|
|
184
|
+
{ code: TAG.DefineFontInfo, offset: fontData.length, data: fontInfoData },
|
|
185
|
+
] });
|
|
186
|
+
const font = symbolTable.get(1);
|
|
187
|
+
|
|
188
|
+
expect(font.codes).toEqual([65]);
|
|
189
|
+
expect(font.name).toBe('Test');
|
|
190
|
+
expect(font.glyphs[0].path[0][0]).toBe('M');
|
|
191
|
+
expect(decodeGlyphShape(glyph).path.length).toBeGreaterThan(3);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('allows empty whitespace outlines and falls back when a visible glyph outline is missing', () => {
|
|
195
|
+
const symbols = new SymbolTable();
|
|
196
|
+
symbols.set(1, { type: 'Font', characterId: 1, version: 2, name: 'Test', codes: [65, 32, 66], glyphs: [
|
|
197
|
+
{ path: [['M', 0, 0], ['L', 100, 0], ['Z']] }, null, null,
|
|
198
|
+
] });
|
|
199
|
+
symbols.set(2, { type: 'Text', characterId: 2, bounds: { xMin: 0, yMin: 0, xMax: 1000, yMax: 300 }, matrix: null, records: [
|
|
200
|
+
{ fontId: 1, fontHeight: 240, x: 0, y: 0, color: '#fff', glyphs: [
|
|
201
|
+
{ glyphIndex: 0, advance: 100 }, { glyphIndex: 1, advance: 100 },
|
|
202
|
+
] },
|
|
203
|
+
] });
|
|
204
|
+
symbols.set(3, { type: 'Text', characterId: 3, bounds: { xMin: 0, yMin: 0, xMax: 1000, yMax: 300 }, matrix: null, records: [
|
|
205
|
+
{ fontId: 1, fontHeight: 240, x: 0, y: 0, color: '#fff', glyphs: [{ glyphIndex: 2, advance: 100 }] },
|
|
206
|
+
] });
|
|
207
|
+
const { characters } = buildDisplayList([], symbols);
|
|
208
|
+
|
|
209
|
+
expect(characters['2'].outlineGlyphRuns[0].glyphs.map((glyph) => glyph.text)).toEqual(['A', ' ']);
|
|
210
|
+
expect(characters['3'].outlineGlyphRuns).toBeUndefined();
|
|
211
|
+
expect(characters['3'].text).toBe('B');
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('decodes layout and paints dynamic Font3 text using the embedded advances and kerning', () => {
|
|
215
|
+
const glyph = tinyGlyph();
|
|
216
|
+
const u16 = value => [value & 255, (value >> 8) & 255];
|
|
217
|
+
const fontData = Uint8Array.of(1, 0, 0x84, 0, 4, ...Buffer.from('Test'), ...u16(2),
|
|
218
|
+
...u16(6), ...u16(6 + glyph.length), ...u16(6 + 2 * glyph.length), ...glyph, ...glyph, ...u16(65), ...u16(66),
|
|
219
|
+
...u16(16384), ...u16(4096), ...u16(-32), ...u16(10240), ...u16(33792), 0, 0,
|
|
220
|
+
...u16(1), ...u16(65), ...u16(66), ...u16(-1024));
|
|
221
|
+
const fontClass = Buffer.from('fixture.Embedded\0');
|
|
222
|
+
const b11 = value => value.toString(2).padStart(11, '0');
|
|
223
|
+
const rect = packBits('01011' + b11(0) + b11(1000) + b11(0) + b11(600));
|
|
224
|
+
const editText = Uint8Array.of(2, 0, ...rect, 0x8c, 0xa3, ...fontClass, ...u16(400), 255, 255, 255, 255,
|
|
225
|
+
0, ...u16(0), ...u16(0), ...u16(-20), ...u16(0), 0, ...Buffer.from('<font kerning="1">AB</font>\0'));
|
|
226
|
+
const { tags, symbolTable } = decode({ tags: [
|
|
227
|
+
{ code: TAG.DefineFont3, offset: 0, data: fontData },
|
|
228
|
+
{ code: TAG.DefineEditText, offset: 0, data: editText },
|
|
229
|
+
{ code: TAG.SymbolClass, offset: 0, data: Uint8Array.of(1, 0, 1, 0, ...fontClass) },
|
|
230
|
+
] });
|
|
231
|
+
expect(symbolTable.get(1).layout).toEqual({ ascent: 16384, descent: 4096, leading: -32,
|
|
232
|
+
advances: [10240, 33792], kerning: [[65, 66, -1024]] });
|
|
233
|
+
expect(symbolTable.get(2)).toMatchObject({ fontClass: 'fixture.Embedded', fontHeight: 400, indent: -20 });
|
|
234
|
+
const displayList = buildDisplayList(tags, symbolTable);
|
|
235
|
+
const engine = generateTimelineEngine(displayList, {});
|
|
236
|
+
const { draw, font, TextField } = runInNewContext(`${SWFLIB_SOURCE}\n${engine}\n({ draw: drawCharacter,
|
|
237
|
+
font: CHARACTERS[1], TextField: __swoof_swflib.builtins.TextField });`, {
|
|
238
|
+
Path2D: class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} },
|
|
239
|
+
});
|
|
240
|
+
const vectorOrigins = [], scales = [], fallback = [];
|
|
241
|
+
let position;
|
|
242
|
+
const ctx = {
|
|
243
|
+
globalAlpha: 1, save() {}, restore() {}, setTransform() {}, beginPath() {}, rect() {}, clip() {},
|
|
244
|
+
translate(x, y) { position = [x, y]; }, scale(x, y) { scales.push([x, y]); },
|
|
245
|
+
fill() { vectorOrigins.push(position); }, fillText(text) { fallback.push(text); },
|
|
246
|
+
};
|
|
247
|
+
draw(ctx, 2, { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 }, 0);
|
|
248
|
+
expect(vectorOrigins).toEqual([[-1, 16], [8, 16]]);
|
|
249
|
+
expect(scales).toEqual([[1 / 1024, 1 / 1024], [1 / 1024, 1 / 1024]]);
|
|
250
|
+
expect(fallback).toEqual([]);
|
|
251
|
+
const text = new TextField();
|
|
252
|
+
text._swoofEmbeddedFont = font;
|
|
253
|
+
text.embedFonts = true;
|
|
254
|
+
Object.assign(text.defaultTextFormat, { font: 'Test', size: 20, kerning: true });
|
|
255
|
+
text.text = 'AB';
|
|
256
|
+
expect(text.textWidth).toBe(42);
|
|
257
|
+
expect(text.getCharBoundaries(1)).toMatchObject({ x: 9, width: 33, height: 20 });
|
|
258
|
+
text.htmlText = '<font kerning="1">AB</font><font kerning="0">AB</font>';
|
|
259
|
+
expect(text.textWidth).toBe(85);
|
|
260
|
+
expect(text.getCharBoundaries(3)).toMatchObject({ x: 52, width: 33 });
|
|
261
|
+
text.htmlText = '<font face="Arial">AB</font>';
|
|
262
|
+
expect(text.textWidth).toBe(20);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it('fits read-only unwrapped DefineEditText paint when the SWF 6 AutoSize flag is set', () => {
|
|
266
|
+
const b11 = value => value.toString(2).padStart(11, '0');
|
|
267
|
+
const rect = packBits('01011' + b11(40) + b11(440) + b11(60) + b11(460));
|
|
268
|
+
const editTag = (id, lowFlags, highFlags) => ({
|
|
269
|
+
code: TAG.DefineEditText,
|
|
270
|
+
data: Uint8Array.of(id, 0, ...rect, lowFlags | 0x80, highFlags | 0x08, 0, ...Buffer.from('short\0')),
|
|
271
|
+
});
|
|
272
|
+
const { tags, symbolTable } = decode({ tags: [
|
|
273
|
+
editTag(1, 0x08, 0x40), // ReadOnly, AutoSize
|
|
274
|
+
editTag(2, 0x08, 0), // fixed read-only field
|
|
275
|
+
editTag(3, 0x68, 0x40), // ReadOnly, WordWrap, Multiline, AutoSize
|
|
276
|
+
editTag(4, 0, 0x40), // editable AutoSize field
|
|
277
|
+
] });
|
|
278
|
+
expect(symbolTable.get(1).autoSize).toBe(true);
|
|
279
|
+
const displayList = buildDisplayList(tags, symbolTable, null, { swfVersion: 6 });
|
|
280
|
+
expect(displayList.characters[1]).toMatchObject({ autoSize: true, bounds: { x: 2, y: 3, w: 20, h: 20 } });
|
|
281
|
+
const olderDisplayList = buildDisplayList(tags, symbolTable, null, { swfVersion: 5 });
|
|
282
|
+
expect(olderDisplayList.characters[1].autoSize).toBeUndefined();
|
|
283
|
+
|
|
284
|
+
const engine = generateTimelineEngine(displayList, {});
|
|
285
|
+
const draw = runInNewContext(`${SWFLIB_SOURCE}\n${engine}\ndrawCharacter;`);
|
|
286
|
+
const matrix = { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 };
|
|
287
|
+
function paint(id, clip = null, forceCanvas = false) {
|
|
288
|
+
const result = { clips: [], borders: [], translations: [] };
|
|
289
|
+
const ctx = {
|
|
290
|
+
globalAlpha: 1, save() {}, restore() {}, setTransform() {}, beginPath() {}, clip() {}, fillText() {},
|
|
291
|
+
measureText: value => ({ width: value.length * 7, fontBoundingBoxAscent: 8, fontBoundingBoxDescent: 2 }),
|
|
292
|
+
rect(...values) { result.clips.push(values); },
|
|
293
|
+
strokeRect(...values) { result.borders.push(values); },
|
|
294
|
+
translate(...values) { result.translations.push(values); },
|
|
295
|
+
};
|
|
296
|
+
draw(ctx, id, matrix, 0, '', undefined, undefined, clip, null, null, forceCanvas);
|
|
297
|
+
return result;
|
|
298
|
+
}
|
|
299
|
+
expect(paint(1)).toEqual({
|
|
300
|
+
clips: [[0, 0, 35, 10]], borders: [[0.5, 0.5, 34, 9]], translations: [[2, 3]],
|
|
301
|
+
});
|
|
302
|
+
expect(paint(1, { text: 'A' }).clips).toEqual([[0, 0, 7, 10]]);
|
|
303
|
+
expect(paint(2).clips).toEqual([[0, 0, 20, 20]]);
|
|
304
|
+
expect(paint(3).clips).toEqual([[0, 0, 20, 20]]);
|
|
305
|
+
expect(paint(4, null, true).clips).toEqual([[0, 0, 20, 20]]);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it('paints the alternate embedded face in Plazma Burst 2’s authored credits links', async () => {
|
|
309
|
+
const diagnostics = new DiagnosticsCollector();
|
|
310
|
+
const { doc } = await parse(readFileSync('archive/Swf/plazma-burst-2.swf'));
|
|
311
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
312
|
+
const symbols = new SymbolTable();
|
|
313
|
+
for (const id of [10, 1072, 1279]) symbols.set(id, symbolTable.get(id));
|
|
314
|
+
const displayList = buildDisplayList([], symbols);
|
|
315
|
+
expect(displayList.characters[1279]).toMatchObject({ outlineFontId: 1072, font: 'DejaVu Sans Mono' });
|
|
316
|
+
expect(displayList.characters[10].name).toBe('EuropeExt');
|
|
317
|
+
|
|
318
|
+
const engine = generateTimelineEngine(displayList, {});
|
|
319
|
+
const draw = runInNewContext(`${SWFLIB_SOURCE}\n${engine}\ndrawCharacter;`, {
|
|
320
|
+
Path2D: class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} },
|
|
321
|
+
});
|
|
322
|
+
const vectorFontSizes = [], fallback = [];
|
|
323
|
+
const ctx = {
|
|
324
|
+
globalAlpha: 1, save() {}, restore() {}, setTransform() {}, translate() {},
|
|
325
|
+
beginPath() {}, rect() {}, clip() {}, fill() {}, fillRect() {},
|
|
326
|
+
scale(x) { vectorFontSizes.push(x * 20480); },
|
|
327
|
+
fillText(text) { fallback.push(text); },
|
|
328
|
+
};
|
|
329
|
+
const matrix = { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 };
|
|
330
|
+
draw(ctx, 1279, matrix, 0);
|
|
331
|
+
expect(vectorFontSizes.filter(size => size === 28)).toHaveLength('Coolbuddy.comwww.PlazmaBurst2.com'.length);
|
|
332
|
+
expect(vectorFontSizes).toContain(12);
|
|
333
|
+
expect(fallback).not.toContain('Coolbuddy.com');
|
|
334
|
+
expect(fallback).not.toContain('www.PlazmaBurst2.com');
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it('uses the regular and bold Arial outlines in Bubble Tanks 2’s authored credits', async () => {
|
|
338
|
+
const { doc } = await parse(readFileSync('archive/Swf/bubble-tanks-2.swf'));
|
|
339
|
+
const { symbolTable } = decode(doc, new DiagnosticsCollector());
|
|
340
|
+
const symbols = new SymbolTable();
|
|
341
|
+
for (const id of [385, 408, 437]) symbols.set(id, symbolTable.get(id));
|
|
342
|
+
const displayList = buildDisplayList([], symbols);
|
|
343
|
+
expect(displayList.characters[437].outlineFontId).toBe(408);
|
|
344
|
+
|
|
345
|
+
const engine = generateTimelineEngine(displayList, {});
|
|
346
|
+
const draw = runInNewContext(`${SWFLIB_SOURCE}\n${engine}\ndrawCharacter;`, {
|
|
347
|
+
Path2D: class {
|
|
348
|
+
moveTo(x, y) { this.firstPoint ??= [x, y]; }
|
|
349
|
+
lineTo() {} quadraticCurveTo() {} closePath() {}
|
|
350
|
+
},
|
|
351
|
+
});
|
|
352
|
+
const glyphs = [];
|
|
353
|
+
let size;
|
|
354
|
+
const ctx = {
|
|
355
|
+
globalAlpha: 1, save() {}, restore() {}, setTransform() {}, translate() {},
|
|
356
|
+
beginPath() {}, rect() {}, clip() {}, fillRect() {}, fillText() {},
|
|
357
|
+
scale(x) { size = x * 20480; },
|
|
358
|
+
fill(path) { glyphs.push({ size, firstPoint: path.firstPoint }); },
|
|
359
|
+
};
|
|
360
|
+
const identity = { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 };
|
|
361
|
+
draw(ctx, 437, identity, 0);
|
|
362
|
+
expect(glyphs.find(glyph => glyph.size === 21)?.firstPoint).toEqual([1500, -14660]); // Bold H.
|
|
363
|
+
expect(glyphs.find(glyph => glyph.size === 14)?.firstPoint).toEqual([1350, -14660]); // Regular h.
|
|
364
|
+
|
|
365
|
+
glyphs.length = 0;
|
|
366
|
+
draw(ctx, 437, identity, 0, '', undefined, undefined, { text: 'h', htmlText: 'h' });
|
|
367
|
+
expect(glyphs[0]?.firstPoint).toEqual([4270, -9270]); // The linked bold face remains the plain-text default.
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it('applies the authored letter spacing to Bubble Tanks 2’s enemy name outlines', async () => {
|
|
371
|
+
const { doc } = await parse(readFileSync('archive/Swf/bubble-tanks-2.swf'));
|
|
372
|
+
const { symbolTable } = decode(doc, new DiagnosticsCollector());
|
|
373
|
+
const symbols = new SymbolTable();
|
|
374
|
+
for (const id of [385, 476, 491]) symbols.set(id, symbolTable.get(id));
|
|
375
|
+
const displayList = buildDisplayList([], symbols);
|
|
376
|
+
expect(displayList.characters[476].text).toContain('letterSpacing="1.000000"');
|
|
377
|
+
for (const id of [476, 491]) {
|
|
378
|
+
expect(displayList.characters[id].csmTextSettings).toEqual({ useFlashType: 1, gridFit: 1, thickness: 0, sharpness: 0 });
|
|
379
|
+
}
|
|
380
|
+
const draw = runInNewContext(`${SWFLIB_SOURCE}\n${generateTimelineEngine(displayList, {})}\ndrawCharacter;`, {
|
|
381
|
+
Path2D: class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} },
|
|
382
|
+
});
|
|
383
|
+
const glyphXs = [];
|
|
384
|
+
let x;
|
|
385
|
+
const ctx = {
|
|
386
|
+
globalAlpha: 1, save() {}, restore() {}, setTransform() {}, scale() {},
|
|
387
|
+
beginPath() {}, rect() {}, clip() {}, translate(glyphX) { x = glyphX; },
|
|
388
|
+
fill() { glyphXs.push(x); },
|
|
389
|
+
};
|
|
390
|
+
draw(ctx, 476, { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 }, 0);
|
|
391
|
+
const font = symbols.get(385);
|
|
392
|
+
const glyphAdvance = char => font.layout.advances[font.codes.indexOf(char.charCodeAt(0))] * 12 / 20480;
|
|
393
|
+
expect(glyphXs[1] - glyphXs[0]).toBeCloseTo(glyphAdvance('e') + 1);
|
|
394
|
+
expect(glyphXs[5] - glyphXs[4]).toBeCloseTo(glyphAdvance('y') + glyphAdvance(' ') + 2);
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
it('decodes usable glyph outlines and attaches them to static text runs in the corpus', async () => {
|
|
398
|
+
for (const [index, file] of corpus.entries()) {
|
|
399
|
+
const bytes = new Uint8Array(readFileSync(file));
|
|
400
|
+
const { doc } = await parse(bytes);
|
|
401
|
+
const { tags, symbolTable } = decode(doc);
|
|
402
|
+
const { characters } = buildDisplayList(tags, symbolTable);
|
|
403
|
+
const fonts = Object.values(characters).filter((character) => character.type === 'font');
|
|
404
|
+
const outlinedFonts = fonts.filter((font) => font.glyphs?.some((glyph) => glyph?.path?.length));
|
|
405
|
+
const staticText = Object.values(characters).filter((character) => character.kind === 'static');
|
|
406
|
+
const outlinedText = staticText.filter((character) => character.outlineGlyphRuns?.length);
|
|
407
|
+
const alignmentTags = tags.filter(tag => tag.code === TAG.DefineFontAlignZones);
|
|
408
|
+
expect(alignmentTags.length, file).toBe([7, 10, 10][index]);
|
|
409
|
+
for (const tag of alignmentTags) {
|
|
410
|
+
const font = symbolTable.get(tag.fontId);
|
|
411
|
+
expect(font.alignmentZones, file).toBe(tag.alignmentZones);
|
|
412
|
+
expect(font.alignmentZones.records, file).toHaveLength(font.glyphs.length);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
expect(outlinedFonts.length, file).toBeGreaterThan(0);
|
|
416
|
+
expect(outlinedText.length, file).toBeGreaterThan(0);
|
|
417
|
+
for (const text of outlinedText) {
|
|
418
|
+
for (const run of text.outlineGlyphRuns) {
|
|
419
|
+
const font = characters[String(run.fontId)];
|
|
420
|
+
expect(font?.glyphs).toBeDefined();
|
|
421
|
+
expect(run.glyphs.every((entry) => font.glyphs[entry.glyphIndex]?.path?.length || /^\s+$/u.test(entry.text || '')), file).toBe(true);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
expect(staticText.length, file).toBeGreaterThanOrEqual(outlinedText.length);
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it.each([
|
|
429
|
+
['archive/flasharchive/PC Breakdown.swf', 284, 287, '0', 'Arial'],
|
|
430
|
+
['archive/flasharchive/Super Mario Flash.swf', 11, 144, 'Mario', 'Courier New TUR'],
|
|
431
|
+
])('uses the linked device-font style in %s', async (file, fontId, textId, text, family) => {
|
|
432
|
+
const { doc } = await parse(readFileSync(file));
|
|
433
|
+
const { symbolTable } = decode(doc, new DiagnosticsCollector());
|
|
434
|
+
const symbols = new SymbolTable();
|
|
435
|
+
for (const id of [fontId, textId]) symbols.set(id, symbolTable.get(id));
|
|
436
|
+
const engine = generateTimelineEngine(buildDisplayList([], symbols), {});
|
|
437
|
+
const draw = runInNewContext(`${SWFLIB_SOURCE}\n${engine}\ndrawCharacter;`);
|
|
438
|
+
const draws = [];
|
|
439
|
+
const ctx = {
|
|
440
|
+
globalAlpha: 1, save() {}, restore() {}, setTransform() {}, translate() {},
|
|
441
|
+
beginPath() {}, rect() {}, clip() {}, fillRect() {}, strokeRect() {},
|
|
442
|
+
fillText(value) { draws.push([value, this.font]); },
|
|
443
|
+
};
|
|
444
|
+
const matrix = { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 };
|
|
445
|
+
const clip = { _swoofAvm1TextField: true, type: 'dynamic' };
|
|
446
|
+
draw(ctx, textId, matrix, 0, '', undefined, undefined, clip);
|
|
447
|
+
expect(draws).toEqual([[text, `bold 14px "${family}"`]]);
|
|
448
|
+
|
|
449
|
+
draws.length = 0;
|
|
450
|
+
clip.htmlText = '<i>' + text + '</i>';
|
|
451
|
+
draw(ctx, textId, matrix, 0, '', undefined, undefined, clip);
|
|
452
|
+
expect(draws).toEqual([[text, `italic bold 14px "${family}"`]]);
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
it.each([
|
|
456
|
+
['archive/flasharchive/PC Breakdown.swf', 287, false, 14],
|
|
457
|
+
['archive/Swf/raze-3.swf', 3668, true, 15],
|
|
458
|
+
])('uses the live Canvas size for authored %s EditText %i', async (file, textId, masked, authoredSize) => {
|
|
459
|
+
const { doc, diagnostics } = await parse(readFileSync(file));
|
|
460
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
461
|
+
const edit = symbolTable.get(textId);
|
|
462
|
+
const symbols = new SymbolTable();
|
|
463
|
+
for (const id of [edit.fontId, textId]) symbols.set(id, symbolTable.get(id));
|
|
464
|
+
const displayList = buildDisplayList([], symbols);
|
|
465
|
+
const engine = generateTimelineEngine(displayList, {});
|
|
466
|
+
const { draw, TextField } = runInNewContext(`${SWFLIB_SOURCE}\n${engine}\n
|
|
467
|
+
({ draw: drawCharacter, TextField: __swoof_swflib.builtins.TextField });`, {
|
|
468
|
+
Path2D: class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} },
|
|
469
|
+
});
|
|
470
|
+
const clip = new TextField();
|
|
471
|
+
clip.type = masked ? 'input' : 'dynamic';
|
|
472
|
+
clip.embedFonts = edit.useOutlines;
|
|
473
|
+
clip.text = edit.initialText;
|
|
474
|
+
const matrix = { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 };
|
|
475
|
+
const units = symbolTable.get(edit.fontId).version === 3 ? 20480 : 1024;
|
|
476
|
+
function renderedSize() {
|
|
477
|
+
const device = [], outlines = [];
|
|
478
|
+
const ctx = {
|
|
479
|
+
globalAlpha: 1, save() {}, restore() {}, setTransform() {}, translate() {},
|
|
480
|
+
beginPath() {}, rect() {}, clip() {}, fill() {},
|
|
481
|
+
measureText: value => ({ width: value.length * 6 }),
|
|
482
|
+
fillText() { device.push(parseFloat(/([\d.]+)px/.exec(this.font)?.[1])); },
|
|
483
|
+
scale(value) { outlines.push(value * units); },
|
|
484
|
+
};
|
|
485
|
+
draw(ctx, textId, matrix, 0, '', undefined, undefined, clip, null, null, masked);
|
|
486
|
+
expect(masked ? device : outlines).toEqual([]);
|
|
487
|
+
return (masked ? outlines : device)[0];
|
|
488
|
+
}
|
|
489
|
+
expect(renderedSize()).toBeCloseTo(authoredSize);
|
|
490
|
+
clip.setTextFormat({ size: 18 });
|
|
491
|
+
expect(renderedSize()).toBeCloseTo(18);
|
|
492
|
+
clip.htmlText = '<font size="20">' + edit.initialText + '</font>';
|
|
493
|
+
expect(renderedSize()).toBeCloseTo(20);
|
|
494
|
+
clip.text = edit.initialText;
|
|
495
|
+
clip.setTextFormat({ size: Infinity });
|
|
496
|
+
expect(renderedSize()).toBeCloseTo(authoredSize);
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
it('retains the authored Nv2 credits link color and applies its rollover format', async () => {
|
|
500
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/Nv2.swf'));
|
|
501
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
502
|
+
const textId = 71;
|
|
503
|
+
const edit = symbolTable.get(textId);
|
|
504
|
+
const symbols = new SymbolTable();
|
|
505
|
+
for (const id of [edit.fontId, textId]) symbols.set(id, symbolTable.get(id));
|
|
506
|
+
expect(edit).toMatchObject({ readOnly: true, html: true, useOutlines: true });
|
|
507
|
+
expect(edit.initialText).toMatch(/<font\b[^>]*color="#000000"[^>]*><a\b/i);
|
|
508
|
+
const engine = generateTimelineEngine(buildDisplayList([], symbols), {});
|
|
509
|
+
const { draw, TextField } = runInNewContext(`${SWFLIB_SOURCE}\n${engine}\n
|
|
510
|
+
({ draw: drawCharacter, TextField: __swoof_swflib.builtins.TextField });`, {
|
|
511
|
+
Path2D: class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} },
|
|
512
|
+
});
|
|
513
|
+
const clip = new TextField();
|
|
514
|
+
clip.embedFonts = true;
|
|
515
|
+
clip.htmlText = edit.initialText;
|
|
516
|
+
const matrix = { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 };
|
|
517
|
+
function paintColors() {
|
|
518
|
+
const colors = new Set();
|
|
519
|
+
const ctx = {
|
|
520
|
+
globalAlpha: 1, save() {}, restore() {}, setTransform() {}, translate() {}, scale() {},
|
|
521
|
+
beginPath() {}, rect() {}, clip() {}, fillRect() {}, fillText() {},
|
|
522
|
+
fill() { colors.add(this.fillStyle); },
|
|
523
|
+
};
|
|
524
|
+
draw(ctx, textId, matrix, 0, '', undefined, undefined, clip);
|
|
525
|
+
return Array.from(colors);
|
|
526
|
+
}
|
|
527
|
+
expect(paintColors()).toEqual(['#000000']);
|
|
528
|
+
|
|
529
|
+
// Nv2 TextLink's authored rollover and rollout handlers set these colors.
|
|
530
|
+
const format = clip.getTextFormat();
|
|
531
|
+
format.color = 0x990000;
|
|
532
|
+
clip.setTextFormat(format);
|
|
533
|
+
expect(paintColors()).toEqual(['#990000']);
|
|
534
|
+
format.color = 0;
|
|
535
|
+
clip.setTextFormat(format);
|
|
536
|
+
expect(paintColors()).toEqual(['#000000']);
|
|
537
|
+
|
|
538
|
+
clip.htmlText = edit.initialText;
|
|
539
|
+
expect(paintColors()).toEqual(['#000000']);
|
|
540
|
+
format.color = 0x990000;
|
|
541
|
+
clip.setTextFormat(format, 0, 1);
|
|
542
|
+
expect(paintColors()).toEqual(['#000000']);
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
it('paints the original Strike Force Heroes HUD feed with per-segment colors', async () => {
|
|
546
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/strike-force-heroes-1.swf'));
|
|
547
|
+
const { tags, symbolTable } = decode(doc, diagnostics);
|
|
548
|
+
const textId = 1463;
|
|
549
|
+
const edit = symbolTable.get(textId);
|
|
550
|
+
const symbols = new SymbolTable();
|
|
551
|
+
for (const id of [edit.fontId, textId]) symbols.set(id, symbolTable.get(id));
|
|
552
|
+
const engine = generateTimelineEngine(buildDisplayList([], symbols), {});
|
|
553
|
+
const { fullJs } = transpileActionScript(tags.filter(tag => tag.type === 'DoABC'), diagnostics,
|
|
554
|
+
{ sharedAvm2Runtime: true, deferAvm2Initializers: true });
|
|
555
|
+
const { hud, field, draw } = runInNewContext(`${SWFLIB_SOURCE}\n${engine}\n${fullJs}
|
|
556
|
+
const hud = Object.create(Hud.prototype);
|
|
557
|
+
const field = new __swoof_swflib.builtins.TextField();
|
|
558
|
+
const info = CHARACTERS[1463];
|
|
559
|
+
field.defaultTextFormat.size = info.fontSize;
|
|
560
|
+
field.textColor = 0xff6600;
|
|
561
|
+
field.embedFonts = true;
|
|
562
|
+
field.htmlText = info.text;
|
|
563
|
+
hud.txt_feed = field;
|
|
564
|
+
hud.__avm2ns_5_abc_659bf256_0_ns_433_txtFmt = new __swoof_swflib.builtins.TextFormat();
|
|
565
|
+
// Use the message text from DefineEditText with the HUD's three-part feed record.
|
|
566
|
+
const parts = field.text.match(/^(.+?)( \\[.+?\\] )(.+)$/).slice(1);
|
|
567
|
+
hud.__avm2ns_5_abc_659bf256_0_ns_433_feeds = [{ txt: parts, col: [0xff6600, 0xcccccc, 0xff5050] }];
|
|
568
|
+
({ hud, field, draw: drawCharacter });
|
|
569
|
+
`, {
|
|
570
|
+
Path2D: class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} },
|
|
571
|
+
});
|
|
572
|
+
hud.processFeed();
|
|
573
|
+
expect(field.text).toBe('Johson [AWP.50 Cal] Richards\n');
|
|
574
|
+
expect(field.defaultTextFormat.size).toBe(12);
|
|
575
|
+
const matrix = { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 };
|
|
576
|
+
function paintColors() {
|
|
577
|
+
const colors = [];
|
|
578
|
+
function record() { if (colors.at(-1) !== this.fillStyle) colors.push(this.fillStyle); }
|
|
579
|
+
const ctx = {
|
|
580
|
+
globalAlpha: 1, save() {}, restore() {}, setTransform() {}, translate() {}, scale() {},
|
|
581
|
+
beginPath() {}, rect() {}, clip() {}, fillRect() {}, fillText: record, fill: record,
|
|
582
|
+
};
|
|
583
|
+
draw(ctx, textId, matrix, 0, '', undefined, undefined, field);
|
|
584
|
+
return colors;
|
|
585
|
+
}
|
|
586
|
+
expect(paintColors()).toEqual(['#ff6600', '#cccccc', '#ff5050']);
|
|
587
|
+
field.text = field.text;
|
|
588
|
+
expect(paintColors()).toEqual(['#ff6600']);
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
it('uses the emitted Canvas font path for Learn to Fly credits that contain empty space glyphs', async () => {
|
|
592
|
+
const { doc } = await parse(new Uint8Array(readFileSync('archive/Swf/learn-to-fly.swf')));
|
|
593
|
+
const { tags, symbolTable } = decode(doc);
|
|
594
|
+
const { characters } = buildDisplayList(tags, symbolTable);
|
|
595
|
+
const { canPaintOutlines } = new Function(`return ${timelineHelpersSource()};`)();
|
|
596
|
+
expect(characters[34].text).toBe('a game by');
|
|
597
|
+
for (const id of [33, 34, 35, 262]) {
|
|
598
|
+
const runs = characters[id].outlineGlyphRuns;
|
|
599
|
+
expect(runs.some(run => run.glyphs.some(glyph => glyph.text === ' '))).toBe(true);
|
|
600
|
+
expect(canPaintOutlines(runs, characters)).toBe(true);
|
|
601
|
+
}
|
|
602
|
+
expect(canPaintOutlines([{ fontId: 10, glyphs: [{ glyphIndex: 0, text: 'A' }] }], characters)).toBe(false);
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
it('emits Canvas outline and browser font painting with a shared text baseline', () => {
|
|
606
|
+
const engine = generateTimelineEngine({ frames: [], characters: {} }, {
|
|
607
|
+
frameRate: 24, frameCount: 1, stageW: 320, stageH: 240, backgroundColor: '#000',
|
|
608
|
+
});
|
|
609
|
+
expect(engine).toContain('drawStaticTextGlyphs(ctx, info, m)');
|
|
610
|
+
expect(engine).toContain('font.version === 3 ? 20 : 1');
|
|
611
|
+
expect(engine).toContain('drawShapePaths(ctx, { draws: [{ path: glyph.path, fill:');
|
|
612
|
+
expect(engine).toContain("ctx.textBaseline = 'alphabetic'");
|
|
613
|
+
expect(engine).toContain('el.style.fontFamily =');
|
|
614
|
+
expect(() => acorn.parse(engine, { ecmaVersion: 2020 })).not.toThrow();
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
it('paints fallback glyphs at authored offsets even when their field bounds are tight', () => {
|
|
618
|
+
const characters = { 1: {
|
|
619
|
+
type: 'text', kind: 'static', bounds: { x: 12, y: 15, w: 6, h: 2 },
|
|
620
|
+
matrix: { a: 1, b: 0, c: 0, d: 1, tx: 40, ty: -20 },
|
|
621
|
+
fallbackGlyphRuns: [{ x: 12, y: 17, font: 'Arial', fontSize: 12, color: '#fff',
|
|
622
|
+
glyphs: [{ text: 'A', advance: 120 }, { text: ' ', advance: 50 }, { text: 'B', advance: 120 }] }],
|
|
623
|
+
} };
|
|
624
|
+
const engine = generateTimelineEngine({ frames: [], characters }, {
|
|
625
|
+
frameRate: 24, frameCount: 1, stageW: 320, stageH: 240, backgroundColor: '#000',
|
|
626
|
+
});
|
|
627
|
+
const draw = runInNewContext(`${engine}\ndrawCharacter`, {});
|
|
628
|
+
const ink = [], matrices = [];
|
|
629
|
+
const ctx = {
|
|
630
|
+
save() {}, restore() {},
|
|
631
|
+
setTransform(...args) { matrices.push(args); },
|
|
632
|
+
fillText(text, x, y) { ink.push([text, x, y, this.textBaseline]); },
|
|
633
|
+
};
|
|
634
|
+
draw(ctx, 1, { a: 1, b: 0, c: 0, d: 1, tx: 20, ty: 60 }, 0);
|
|
635
|
+
expect(matrices).toEqual([[1, 0, 0, 1, 3, 2]]);
|
|
636
|
+
expect(ink).toEqual([['A', 12, 17, 'alphabetic'], ['B', 20.5, 17, 'alphabetic']]);
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
it('paints read-only variable text on Canvas from its own timeline scope', () => {
|
|
640
|
+
const characters = { 1: {
|
|
641
|
+
type: 'text', kind: 'edit', bounds: { x: 2, y: 3, w: 80, h: 25 },
|
|
642
|
+
text: '<b>Text</b>', html: true, variableName: '_parent.message', color: '#fff',
|
|
643
|
+
} };
|
|
644
|
+
const engine = generateTimelineEngine({ frames: [], characters }, { frameCount: 1 });
|
|
645
|
+
const scope = { root: { message: 'Wrong' } };
|
|
646
|
+
const draw = runInNewContext(`${SWFLIB_SOURCE}\n${engine}\ndrawCharacter`, { window: { __swoof: scope } });
|
|
647
|
+
const ink = [], matrices = [];
|
|
648
|
+
const ctx = {
|
|
649
|
+
save() {}, restore() {}, translate() {}, beginPath() {}, rect() {}, clip() {},
|
|
650
|
+
measureText(text) { return { width: String(text).length * 8 }; },
|
|
651
|
+
setTransform(...args) { matrices.push(args); },
|
|
652
|
+
fillText(text) { ink.push(text); },
|
|
653
|
+
};
|
|
654
|
+
const matrix = { a: 0.5, b: 0.1, c: 0.2, d: 0.5, tx: 40, ty: 60 };
|
|
655
|
+
draw(ctx, 1, matrix, 0, '', null, null, null, { parent: { message: 'Correct' } });
|
|
656
|
+
expect(matrices).toEqual([[0.5, 0.1, 0.2, 0.5, 2, 3]]);
|
|
657
|
+
expect(ink).toEqual(['Correct']);
|
|
658
|
+
});
|
|
659
|
+
});
|