void DefineEditTextTag::read(SWFStream& in, movie_definition& m) { _rect = readRect(in); in.align(); in.ensureBytes(2); int flags = in.read_u8(); _hasText = flags & (1 << 7); _wordWrap = flags & (1 << 6); _multiline = flags & (1 << 5); _password = flags & (1 << 4); _readOnly = flags & (1 << 3); const bool hasColor = flags & (1 << 2); const bool hasMaxChars = flags & (1 << 1); const bool hasFont = flags & (1 << 0); flags = in.read_u8(); // 0: no font class, 1 font class and height, can't be true if has_font was true bool hasFontClass = flags & (1 << 7); if (hasFontClass && hasFont ) { IF_VERBOSE_MALFORMED_SWF( log_swferror("DefineEditText: hasFontClass can't be true if " "hasFont is true, ignoring"); );
/// Format of the bit-packed rectangle is: /// /// bits | name | description /// ------+-------+------------------------- /// 5 | nbits | number of bits used in subsequent values /// nbits | xmin | minimum X value /// nbits | xmax | maximum X value /// nbits | ymin | minimum Y value /// nbits | ymax | maximum Y value /// /// If max values are less then min values the SWF is malformed; /// in this case this method will raise an swf_error and set the /// rectangle to the NULL rectangle. See is_null(). SWFRect readRect(SWFStream& in) { in.align(); in.ensureBits(5); const int nbits = in.read_uint(5); int minx = 0, maxx = 0, miny = 0, maxy = 0; if (nbits > 0) { in.ensureBits(nbits*4); minx = in.read_sint(nbits); maxx = in.read_sint(nbits); miny = in.read_sint(nbits); maxy = in.read_sint(nbits); } // Check if this SWFRect is valid. if (maxx < minx || maxy < miny) { // We set invalid rectangles to NULL, but we might instead // want to actually swap the values if the proprietary player // does so. TODO: check it out. IF_VERBOSE_MALFORMED_SWF( log_swferror(_("Invalid rectangle: " "minx=%g maxx=%g miny=%g maxy=%g"), minx, maxx, miny, maxy); );
SWFMatrix readSWFMatrix(SWFStream& in) { in.align(); in.ensureBits(1); const bool has_scale = in.read_bit(); std::int32_t sx = 65536; std::int32_t sy = 65536; if (has_scale) { in.ensureBits(5); const std::uint8_t scale_nbits = in.read_uint(5); if (scale_nbits) { in.ensureBits(scale_nbits * 2); sx = in.read_sint(scale_nbits); sy = in.read_sint(scale_nbits); } } in.ensureBits(1); const bool has_rotate = in.read_bit(); std::int32_t shx = 0; std::int32_t shy = 0; if (has_rotate) { in.ensureBits(5); unsigned int rotate_nbits = in.read_uint(5); if (rotate_nbits) { in.ensureBits(rotate_nbits * 2); shx = in.read_sint(rotate_nbits); shy = in.read_sint(rotate_nbits); } } in.ensureBits(5); const std::uint8_t translate_nbits = in.read_uint(5); std::int32_t tx = 0; std::int32_t ty = 0; if (translate_nbits) { in.ensureBits(translate_nbits * 2); tx = in.read_sint(translate_nbits); ty = in.read_sint(translate_nbits); } return SWFMatrix(sx, shx, shy, sy, tx, ty); }
void DefineMorphShapeTag::read(SWFStream& in, TagType tag, movie_definition& md, const RunResources& r) { assert(tag == DEFINEMORPHSHAPE || tag == DEFINEMORPHSHAPE2 || tag == DEFINEMORPHSHAPE2_); const SWFRect bounds1 = readRect(in); const SWFRect bounds2 = readRect(in); if (tag == DEFINEMORPHSHAPE2 || tag == DEFINEMORPHSHAPE2_) { // TODO: Use these values. const SWFRect innerBound1 = readRect(in); const SWFRect innerBound2 = readRect(in); UNUSED(innerBound1); UNUSED(innerBound2); // This should be used -- first 6 bits reserved, then // 'non-scaling' stroke, then 'scaling' stroke -- these can be // used to optimize morphing. in.ensureBytes(1); static_cast<void>(in.read_u8()); } in.ensureBytes(4); // Offset. What is this for? static_cast<void>(in.read_u32()); // Next line will throw ParserException on malformed SWF const boost::uint16_t fillCount = in.read_variable_count(); for (size_t i = 0; i < fillCount; ++i) { OptionalFillPair fp = readFills(in, tag, md, true); _shape1.addFillStyle(fp.first); _shape2.addFillStyle(*fp.second); } const boost::uint16_t lineCount = in.read_variable_count(); LineStyle ls1, ls2; for (size_t i = 0; i < lineCount; ++i) { ls1.read_morph(in, tag, md, r, &ls2); _shape1.addLineStyle(ls1); _shape2.addLineStyle(ls2); } _shape1.read(in, tag, md, r); in.align(); _shape2.read(in, tag, md, r); // Set bounds as read in *this* tags rather then // the one computed from ShapeRecord parser // (does it make sense ?) _shape1.setBounds(bounds1); _shape2.setBounds(bounds2); // Starting bounds are the same as shape1 _bounds = bounds1; assert(_shape1.fillStyles().size() == _shape2.fillStyles().size()); assert(_shape1.lineStyles().size() == _shape2.lineStyles().size()); }