Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Next

- **[Breaking change]** Update to `swf-tree@0.7`.

# 0.5.4 (2019-05-20)

- **[Feature]** Implement parser for `DefineFont2` ([#38](https://github.com/open-flash/swf-parser/issues/38)).
Expand Down
27 changes: 18 additions & 9 deletions rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ lazy_static = "^1.3.0"
lzma-rs = "^0.1.1"
memchr = "^2.2.0"
nom = "^4.2.3"
num-traits = "^0.2.6"
regex = "^1.1.5"
num-traits = "^0.2.7"
regex = "^1.1.6"
serde_json = "^1.0.39"
swf-tree = "^0.6.0"
swf-tree = "^0.7.0"
swf-fixed = "^0.1.4"

[dev-dependencies]
Expand Down
21 changes: 14 additions & 7 deletions rs/src/parsers/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::parsers::morph_shape::{MorphShapeVersion, parse_morph_shape};
use crate::parsers::movie::parse_tag_block_string;
use crate::parsers::shape::{parse_shape, ShapeVersion};
use crate::parsers::sound::{audio_coding_format_from_id, is_uncompressed_audio_coding_format, parse_sound_info, sound_rate_from_id};
use crate::parsers::text::{parse_csm_table_hint_bits, parse_font_alignment_zone, parse_font_layout, parse_grid_fitting_bits, parse_offset_glyphs, parse_text_alignment, parse_text_record_string, parse_text_renderer_bits};
use crate::parsers::text::{parse_csm_table_hint_bits, parse_font_alignment_zone, parse_font_layout, parse_grid_fitting_bits, parse_offset_glyphs, parse_text_alignment, parse_text_record_string, parse_text_renderer_bits, FontVersion};
use crate::state::ParseState;

fn parse_tag_header(input: &[u8]) -> IResult<&[u8], ast::TagHeader> {
Expand Down Expand Up @@ -376,7 +376,7 @@ pub fn parse_define_edit_text(input: &[u8]) -> IResult<&[u8], ast::tags::DefineD
font_size: font_size,
color: color,
max_length: max_length,
align: Some(align),
align: align,
margin_left: margin_left,
margin_right: margin_right,
indent: indent,
Expand All @@ -392,17 +392,15 @@ pub fn parse_define_font(_input: &[u8]) -> IResult<&[u8], ast::tags::DefineFont>
}

pub fn parse_define_font2(input: &[u8]) -> IResult<&[u8], ast::tags::DefineFont> {
// TODO: Add a flag to signal that this defineFont comes from `DefineFont2` (to support proper glyph scaling)
parse_define_font_any(input)
parse_define_font_any(input, FontVersion::Font2)
}

pub fn parse_define_font3(input: &[u8]) -> IResult<&[u8], ast::tags::DefineFont> {
// TODO: Add a flag to signal that this defineFont comes from `DefineFont3` (to support proper glyph scaling)
parse_define_font_any(input)
parse_define_font_any(input, FontVersion::Font3)
}

// https://github.com/mozilla/shumway/blob/16451d8836fa85f4b16eeda8b4bda2fa9e2b22b0/src/swf/parser/module.ts#L632
pub fn parse_define_font_any(input: &[u8]) -> IResult<&[u8], ast::tags::DefineFont> {
fn parse_define_font_any(input: &[u8], version: FontVersion) -> IResult<&[u8], ast::tags::DefineFont> {
do_parse!(
input,
id: parse_le_u16 >>
Expand All @@ -415,6 +413,13 @@ pub fn parse_define_font_any(input: &[u8]) -> IResult<&[u8], ast::tags::DefineFo
is_small: value!((flags & (1 << 5)) != 0) >>
is_shift_jis: value!((flags & (1 << 6)) != 0) >>
has_layout: value!((flags & (1 << 7)) != 0) >>
em_square_size: value!(
if version >= FontVersion::Font3 {
ast::text::EmSquareSize::EmSquareSize20480
} else {
ast::text::EmSquareSize::EmSquareSize1024
}
) >>
language: parse_language_code >>
font_name: length_value!(parse_u8, parse_block_c_string) >>
glyph_count: map!(parse_le_u16, |x| x as usize) >>
Expand All @@ -425,6 +430,7 @@ pub fn parse_define_font_any(input: &[u8]) -> IResult<&[u8], ast::tags::DefineFo
true => value!(ast::tags::DefineFont {
id, font_name,
is_bold, is_italic, is_ansi, is_small, is_shift_jis,
em_square_size,
language,
glyphs: Option::None,
code_units: Option::None,
Expand All @@ -443,6 +449,7 @@ pub fn parse_define_font_any(input: &[u8]) -> IResult<&[u8], ast::tags::DefineFo
(ast::tags::DefineFont {
id, font_name,
is_bold, is_italic, is_ansi, is_small, is_shift_jis,
em_square_size,
language,
glyphs: Option::Some(glyphs),
code_units: Option::Some(code_units),
Expand Down
8 changes: 8 additions & 0 deletions rs/src/parsers/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ use crate::parsers::basic_data_types::{
};
use crate::parsers::shape::parse_glyph;

#[derive(PartialEq, Eq, Clone, Copy, Ord, PartialOrd)]
pub enum FontVersion {
Font1,
Font2,
Font3,
Font4,
}

pub fn parse_grid_fitting_bits(input: (&[u8], usize)) -> IResult<(&[u8], usize), ast::text::GridFitting> {
switch!(
input,
Expand Down
2 changes: 1 addition & 1 deletion tests/movies
Submodule movies updated 1 files
+1 −0 hello-world/ast.json
6 changes: 3 additions & 3 deletions ts/gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ const project: Project = {
configuration: {
rules: {
"whitespace": false,
}
}
}
},
},
},
};

const lib: LibTarget = {
Expand Down
4 changes: 2 additions & 2 deletions ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"incident": "^3.2.0",
"pako": "^1.0.10",
"semantic-types": "^0.1.1",
"swf-tree": "^0.6.0"
"swf-tree": "^0.7.0"
},
"devDependencies": {
"@types/chai": "^4.1.7",
Expand All @@ -45,7 +45,7 @@
"@types/node": "^11.13.10",
"bson": "^4.0.1",
"chai": "^4.2.0",
"gulp": "^4.0.1",
"gulp": "^4.0.2",
"gulp-cli": "^2.2.0",
"kryo": "^0.8.1",
"minimist": "^1.2.0",
Expand Down
19 changes: 9 additions & 10 deletions ts/src/lib/parsers/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { SoundType } from "swf-tree/sound/sound-type";
import { SpriteTag } from "swf-tree/sprite-tag";
import { TagHeader } from "swf-tree/tag-header";
import { TextAlignment } from "swf-tree/text";
import { EmSquareSize } from "swf-tree/text/em-square-size";
import { GlyphCountProvider, ParseContext } from "../parse-context";
import {
parseBlockCString,
Expand Down Expand Up @@ -67,6 +68,7 @@ import {
parseSoundInfo,
} from "./sound";
import {
FontVersion,
parseCsmTableHintBits,
parseFontAlignmentZone,
parseFontLayout,
Expand All @@ -82,7 +84,6 @@ import {
* Read tags until the end of the stream or "end-of-tags".
*/
export function parseTagBlockString(byteStream: ReadableByteStream, context: ParseContext): Tag[] {
let old: UintSize = byteStream.bytePos;
const tags: Tag[] = [];
while (byteStream.available() >= 2) {
// A null byte indicates the end-of-tags
Expand All @@ -98,10 +99,6 @@ export function parseTagBlockString(byteStream: ReadableByteStream, context: Par
}
}
const tag: Tag = parseTag(byteStream, context);
if (tag.type === TagType.DefineFont && tags.length === 3850) {
console.log(old, byteStream.bytePos);
}
old = byteStream.bytePos;
tags.push(tag);
}
return tags;
Expand Down Expand Up @@ -496,17 +493,15 @@ export function parseDefineFont(_byteStream: ReadableByteStream): tags.DefineFon
}

export function parseDefineFont2(byteStream: ReadableByteStream): tags.DefineFont {
// TODO: Add a flag to signal that this defineFont comes from `DefineFont2` (to support proper glyph scaling)
return parseDefineFontAny(byteStream);
return parseDefineFontAny(byteStream, FontVersion.Font2);
}

export function parseDefineFont3(byteStream: ReadableByteStream): tags.DefineFont {
// TODO: Add a flag to signal that this defineFont comes from `DefineFont3` (to support proper glyph scaling)
return parseDefineFontAny(byteStream);
return parseDefineFontAny(byteStream, FontVersion.Font3);
}

// https://github.com/mozilla/shumway/blob/16451d8836fa85f4b16eeda8b4bda2fa9e2b22b0/src/swf/parser/module.ts#L632
export function parseDefineFontAny(byteStream: ReadableByteStream): tags.DefineFont {
function parseDefineFontAny(byteStream: ReadableByteStream, version: FontVersion): tags.DefineFont {
const id: Uint16 = byteStream.readUint16LE();

const flags: Uint8 = byteStream.readUint8();
Expand All @@ -519,6 +514,8 @@ export function parseDefineFontAny(byteStream: ReadableByteStream): tags.DefineF
const isShiftJis: boolean = (flags & (1 << 6)) !== 0;
const hasLayout: boolean = (flags & (1 << 7)) !== 0;

const emSquareSize: EmSquareSize = version >= FontVersion.Font3 ? 20480 : 1024;

const language: LanguageCode = parseLanguageCode(byteStream);
const fontNameLength: UintSize = byteStream.readUint8();
const fontName: string = parseBlockCString(byteStream, fontNameLength);
Expand All @@ -539,6 +536,7 @@ export function parseDefineFontAny(byteStream: ReadableByteStream): tags.DefineF
isAnsi,
isSmall,
isShiftJis,
emSquareSize,
language,
};
}
Expand All @@ -558,6 +556,7 @@ export function parseDefineFontAny(byteStream: ReadableByteStream): tags.DefineF
isAnsi,
isSmall,
isShiftJis,
emSquareSize,
language,
glyphs,
codeUnits,
Expand Down
7 changes: 7 additions & 0 deletions ts/src/lib/parsers/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import { Glyph, LanguageCode, Rect, StraightSRgba8, text } from "swf-tree";
import { parseRect, parseSRgb8, parseStraightSRgba8 } from "./basic-data-types";
import { parseGlyph } from "./shape";

export enum FontVersion {
Font1 = 1,
Font2 = 2,
Font3 = 3,
Font4 = 4,
}

export function parseGridFittingBits(bitStream: ReadableBitStream): text.GridFitting {
const code: UintSize = bitStream.readUint32Bits(3);
switch (code) {
Expand Down
32 changes: 16 additions & 16 deletions ts/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
esutils "^2.0.2"
js-tokens "^4.0.0"

"@babel/parser@^7.4.4":
version "7.4.4"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.4.4.tgz#5977129431b8fe33471730d255ce8654ae1250b6"
integrity sha512-5pCS4mOsL+ANsFZGdvNLybx4wtqAZJ0MJjMHxvzI3bvIsz6sQvzW8XX92EYIkiPtIvcfG3Aj+Ir5VNyjnZhP7w==
"@babel/parser@^7.4.4", "@babel/parser@^7.4.5":
version "7.4.5"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.4.5.tgz#04af8d5d5a2b044a2a1bffacc1e5e6673544e872"
integrity sha512-9mUqkL1FF5T7f0WDFfAoDdiMVPWsdD1gZYzSnaXsxUCUqzuch/8of9G3VUSNiZmMBoRxT3neyVsqeiL/ZPcjew==

"@babel/template@^7.1.0":
version "7.4.4"
Expand All @@ -67,15 +67,15 @@
"@babel/types" "^7.4.4"

"@babel/traverse@^7.4.4":
version "7.4.4"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.4.4.tgz#0776f038f6d78361860b6823887d4f3937133fe8"
integrity sha512-Gw6qqkw/e6AGzlyj9KnkabJX7VcubqPtkUQVAwkc0wUMldr3A/hezNB3Rc5eIvId95iSGkGIOe5hh1kMKf951A==
version "7.4.5"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.4.5.tgz#4e92d1728fd2f1897dafdd321efbff92156c3216"
integrity sha512-Vc+qjynwkjRmIFGxy0KYoPj4FdVDxLej89kMHFsWScq999uX+pwcX4v9mWRjW0KcAYTPAuVQl2LKP1wEVLsp+A==
dependencies:
"@babel/code-frame" "^7.0.0"
"@babel/generator" "^7.4.4"
"@babel/helper-function-name" "^7.1.0"
"@babel/helper-split-export-declaration" "^7.4.4"
"@babel/parser" "^7.4.4"
"@babel/parser" "^7.4.5"
"@babel/types" "^7.4.4"
debug "^4.1.0"
globals "^11.1.0"
Expand Down Expand Up @@ -1958,7 +1958,7 @@ gulp-typescript@^5.0.1:
vinyl "^2.1.0"
vinyl-fs "^3.0.3"

gulp@^4.0.1:
gulp@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/gulp/-/gulp-4.0.2.tgz#543651070fd0f6ab0a0650c6a3e6ff5a7cb09caa"
integrity sha512-dvEs27SCZt2ibF29xYgmnwwCYZxdxhQ/+LFWlbAW8y7jt68L/65402Lz3+CKy0Ov4rOs+NERmDq7YlZaDqUIfA==
Expand Down Expand Up @@ -3999,10 +3999,10 @@ sver-compat@^1.5.0:
es6-iterator "^2.0.1"
es6-symbol "^3.1.1"

swf-tree@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/swf-tree/-/swf-tree-0.6.0.tgz#57362bdc070d4be1dd71ee6b43753fe33b1c275f"
integrity sha512-5ZAGao4LhVHQ74NieRZAYsMeabSpDkRQNLLQDCalmVMvzlCIAYQWzijm2DX9VZp8V4cjW97gEZxfPGpQ1N1ToQ==
swf-tree@^0.7.0:
version "0.7.0"
resolved "https://registry.yarnpkg.com/swf-tree/-/swf-tree-0.7.0.tgz#76db2876b83832a761cfdf62130c3b764f0a82b1"
integrity sha512-kYOimbeZKTW6Bt/cfzLx1HnclWZjtgR5MCa+ulU1nQiXiFKRBNDQK0kr96OOTtbrI6DgzgG50+eE99qkr1DA5A==
dependencies:
incident "^3.2.0"
kryo "^0.8.1"
Expand Down Expand Up @@ -4304,9 +4304,9 @@ typescript@^3.5.0-dev.20190430:
integrity sha512-8Os3bqTeHc6bf+bkPFL3O/pb09j8SbDa2LUBxTXWpZlcHUW9ziGuiEFiqMcArkbAjGLqEzshkl4zvxhb0gVPuQ==

uglify-js@^3.1.4:
version "3.5.14"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.5.14.tgz#edf2a322c37fd7173a954fb35af199b52fb10946"
integrity sha512-dgyjIw8KFK6AyVl5vm2tEqPewv5TKGEiiVFLI1LbF+oHua/Njd8tZk3lIbF1AWU1rNdEg7scaceADb4zqCcWXg==
version "3.5.15"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.5.15.tgz#fe2b5378fd0b09e116864041437bff889105ce24"
integrity sha512-fe7aYFotptIddkwcm6YuA0HmknBZ52ZzOsUxZEdhhkSsz7RfjHDX2QDxwKTiv4JQ5t5NhfmpgAK+J7LiDhKSqg==
dependencies:
commander "~2.20.0"
source-map "~0.6.1"
Expand Down