Example #1
0
void touchmind::print::XPSPrint::_PrintNodes(const std::shared_ptr<touchmind::model::node::NodeModel> &node)
{
    PrintChildrenLinksVisitor linksVisitor(this);
    node->ApplyVisitor(linksVisitor);

    PrintNodeVisitor printNodeVisitor(this);
    node->ApplyVisitor(printNodeVisitor);
}
void touchmind::converter::NodeModelToTextConverter::ToText(
    const std::shared_ptr<touchmind::model::node::NodeModel> &node, std::wstring &text) {
    std::wostringstream stream;
    ConvertToTextTreeVisitor visitor(stream);
    node->ApplyVisitor(visitor, true);
    text = stream.str();
}
void touchmind::print::XPSGeometryBuilder::CalculateTransformMatrix(
    const XPS_SIZE &pageSize,
    const XPSPRINT_MARGIN &xpsMargin,
    std::shared_ptr<touchmind::model::node::NodeModel> node,
    OUT XPS_MATRIX &xpsMatrix,
    OUT FLOAT &scale)
{
    touchmind::layout::TreeRectVisitor treeRectVisitor;
    node->ApplyVisitor(treeRectVisitor);

    FLOAT width_p = pageSize.width - xpsMargin.left - xpsMargin.right;
    FLOAT height_p = pageSize.height - xpsMargin.top - xpsMargin.bottom;

    FLOAT width_m = treeRectVisitor.treeRect.x2 - treeRectVisitor.treeRect.x1;
    FLOAT height_m = treeRectVisitor.treeRect.y2 - treeRectVisitor.treeRect.y1;

    D2D1_MATRIX_3X2_F translationMatrix;
    D2D1_MATRIX_3X2_F scaleMatrix;
    FLOAT rx = width_p / width_m;
    FLOAT ry = height_p / height_m;
    FLOAT cx = treeRectVisitor.treeRect.x1 + width_m / 2.0f;
    FLOAT cy = treeRectVisitor.treeRect.y1 + height_m / 2.0f;
    if (rx >= 1.0f && ry >= 1.0f) {
        translationMatrix = D2D1::Matrix3x2F::Translation(
                                width_p / 2.0f + xpsMargin.left - cx,
                                height_p / 2.0f + xpsMargin.top - cy );
        scale = 1.0f;
    } else if (rx < ry) {
        translationMatrix = D2D1::Matrix3x2F::Translation(
                                width_p / 2.0f + xpsMargin.left - cx * rx,
                                height_p / 2.0f + xpsMargin.top - cy * rx );
        scale = rx;
    } else {
        translationMatrix = D2D1::Matrix3x2F::Translation(
                                width_p / 2.0f + xpsMargin.left - cx * ry,
                                height_p / 2.0f + xpsMargin.top - cy * ry );
        scale = ry;
    }

    scaleMatrix = D2D1::Matrix3x2F::Scale(scale, scale, D2D1::Point2F(0.0f, 0.0f));
    D2D1_MATRIX_3X2_F matrix = scaleMatrix * translationMatrix;

    xpsMatrix.m11 = matrix._11;
    xpsMatrix.m12 = matrix._12;
    xpsMatrix.m21 = matrix._21;
    xpsMatrix.m22 = matrix._22;
    xpsMatrix.m31 = matrix._31;
    xpsMatrix.m32 = matrix._32;
}