Example #1
0
std::ostream&
operator<<(std::ostream& o, const SWFMatrix& m)
{
    // 8 digits and a decimal point.
    const short fieldWidth = 9;

    o << std::endl << "|"
      << std::setw(fieldWidth) << std::fixed << std::setprecision(4) 
      << m.a() / 65536.0 << " "
      << std::setw(fieldWidth) << std::fixed << std::setprecision(4) 
      << m.c()/ 65536.0 << " "
      << std::setw(fieldWidth) << std::fixed << std::setprecision(4) 
      << twipsToPixels(m.tx()) << " |" 
      << std::endl << "|"
      << std::setw(fieldWidth) << std::fixed << std::setprecision(4) 
      << m.b()/ 65536.0 << " "
      << std::setw(fieldWidth) << std::fixed << std::setprecision(4) 
      << m.d() / 65536.0 << " "
      << std::setw(fieldWidth) << std::fixed << std::setprecision(4) 
      << twipsToPixels(m.ty()) << " |";
      
      return o;
}
Example #2
0
void
TextSnapshot_as::getTextRunInfo(size_t start, size_t end, as_object& ri) const
{
    std::string::size_type pos = 0;

    std::string::size_type len = end - start;

    for (TextFields::const_iterator field = _textFields.begin(),
            e = _textFields.end(); field != e; ++field) {

        const Records& rec = field->second;
        const SWFMatrix& mat = getMatrix(*field->first);
        const boost::dynamic_bitset<>& selected = field->first->getSelected();

        const std::string::size_type fieldStartIndex = pos;

        for (Records::const_iterator j = rec.begin(), end = rec.end();
                j != end; ++j) {
        
            const SWF::TextRecord* tr = *j;
            assert(tr);

            const SWF::TextRecord::Glyphs& glyphs = tr->glyphs();
            const SWF::TextRecord::Glyphs::size_type numGlyphs = glyphs.size();

            if (pos + numGlyphs < start) {
                pos += numGlyphs;
                continue;
            }

            const Font* font = tr->getFont();
            assert(font);

            double x = tr->xOffset();
            for (SWF::TextRecord::Glyphs::const_iterator k = glyphs.begin(),
                    e = glyphs.end(); k != e; ++k) {
                
                if (pos < start) {
                    x += k->advance;
                    ++pos;
                    continue;
                }
                
                as_object* el = new as_object(getGlobal(ri));

                el->init_member("indexInRun", pos);
                el->init_member("selected",
                        selected.test(pos - fieldStartIndex));
                el->init_member("font", font->name());
                el->init_member("color", tr->color().toRGBA());
                el->init_member("height", twipsToPixels(tr->textHeight()));

                const double factor = 65536.0;
                el->init_member("matrix_a", mat.a() / factor);
                el->init_member("matrix_b", mat.b() / factor);
                el->init_member("matrix_c", mat.c() / factor);
                el->init_member("matrix_d", mat.d() / factor);

                const double xpos = twipsToPixels(mat.tx() + x);
                const double ypos = twipsToPixels(mat.ty() + tr->yOffset());
                el->init_member("matrix_tx", xpos);
                el->init_member("matrix_ty", ypos);

                callMethod(&ri, NSV::PROP_PUSH, el);

                ++pos;
                x += k->advance;
                if (pos - start > len) return;
            }
        }
    }
    
}