Skip to main content
Participant
April 8, 2014
Answered

Changing page size, unexpected behavior, CC

  • April 8, 2014
  • 1 reply
  • 957 views

Hi, having an issue with transformations after changing the page. In a nut shell if I get the pasteboard transformation of PMPoint(0,0) before a page size change the result is exactly as expected, the page origin in the pasteboard. After I change the page size using kSetPageSetupPrefsCmdBoss and run the same tranformation the retuned value is the same as before changing the page size.

Below is some quick code and output to illustrate. PageSizing:;DoYourThing() get called and does the intial transformation, prints the output in InspectTransformation(), then calls ChangePageSize() and recalls InspectTransformation().

void PageSizing::DoYourThing()

{

    IDocument* theFrontDoc = Utils<ILayoutUIUtils>()->GetFrontDocument();

          if (theFrontDoc == nil) { cout << "Need a doc." << endl; return; }

    fDoc = theFrontDoc;

    GetPageSpreadRefs(1); // Get the UIDRef of 1st apge and spread

    if (fPageRef == UIDRef::gNull) { cout << "Invalid page UIDRef." << endl; return; }

    if (fSpreadRef == UIDRef::gNull) { cout << "Invalid spread UIDRef." << endl; return; }

    cout << "Before Page Size Change." << endl;

    InspectTranforms();

    bool16 sizeChangeResult = ChangePageSize();

    if (sizeChangeResult) {

        cout << "After Page Size Change." << endl;

        InspectTranforms();

    }

}

void PageSizing::InspectTranforms()

{

    do {

        PMPoint leftTopPage(0, 0); // Page coords

        InterfacePtr<IGeometry> pageGeo(fPageRef, UseDefaultIID());

        PMMatrix page2Pb = ::InnerToPasteboardMatrix(pageGeo);

        PMRect pageBoundsInPasteboard = pageGeo->GetStrokeBoundingBox(page2Pb);

        PMPoint pageOriginInPasteboard = pageBoundsInPasteboard.LeftTop();

        Helper::PrintPoint(pageOriginInPasteboard, "Page origin in paste board.");

        InterfacePtr<ITransform> pageTransform(fPageRef, UseDefaultIID());

        PMPoint leftTopInPasteboard = leftTopPage;

        ::TransformInnerPointToPasteboard(pageTransform, &leftTopInPasteboard);

        Helper::PrintPoint(leftTopInPasteboard, "Transformed point (0,0) in pasteboard coords.");

    } while (kFalse);

}

bool16 PageSizing::ChangePageSize()

{

    bool16 retval = kFalse;

    do {

        InterfacePtr<IPageSetupPrefs> docPrefs(fDoc->GetDocWorkSpace(), UseDefaultIID());

        if (docPrefs == nil) { cout << "Nil IPageSetupPrefs" << endl; break; }

        InterfacePtr<ICommand> pageSizeCmd(CmdUtils::CreateCommand(kSetPageSetupPrefsCmdBoss));

        if (pageSizeCmd == nil) { cout << "Nil command" << endl; break; }

        InterfacePtr<IDocSetupCmdData> cmdData(pageSizeCmd, IID_IDOCSETUPCMDDATA);

        if (cmdData == nil) { cout << "Nil command data" << endl; break; }

        PMPageSize currPgSz = docPrefs->GetPageSizePref(); // 612, 792

        PMPageSize newPgSz(currPgSz.OutputWidth() + 50, currPgSz.OutputHeight() + 50);

        DocPageBinding binding = Utils<ILayoutUtils>()->GetDocumentPageBinding(::GetUIDRef(fDoc));

        cmdData->SetDocSetupCmdData(    ::GetUIDRef(fDoc),

                                    newPgSz,

                                    docPrefs->GetNumPagesPref(),

                                    docPrefs->GetPagesPerSpreadPref(),

                                    docPrefs->GetWideOrientationPref(),

                                    binding);

        ErrorCode ec = CmdUtils::ProcessCommand(pageSizeCmd);

        retval = (ec == kSuccess);

        if (! retval) { cout << "Resize page command failed." << endl; }

    } while (kFalse);

    return retval;

}

The output

As you can see the page origin is different after the page size command but the transform returns the same value for 0,0.

Am I missing something on the transformations or the page size command?

Thanks for any help. Mike

This topic has been closed for replies.
Correct answer Markus Freitag

Hello Mike,

you wasn't assuming that the top left of a page in pasteborad coordinates is (0, 0). That's correct. But you assuming that the top left of a page in inner coordinates is (0, 0). And that is wrong. The page origin in inner coodinates is not (0, 0) after resizing.

Markus

1 reply

Inspiring
April 8, 2014

Hello Mike,

it is all ok. But your assumption that the left top of a page in inner coordinates is always (0, 0) is wrong. The left top of a page changes if you resize the page. Never use (0, 0) hardcoded for the origin.

Markus

M.MarconiAuthor
Participant
April 8, 2014

Hey Markus, I wasn't assuming that the top left of any page in pasteboard coords is 0,0. My point is when getting a pasteboard transfrom for point 0,0 one would always expect it to be the same as the page origin (topLeft) in the same pasteboard space. And it's not when the page size has been changed via the referenced command.

Mike

Markus FreitagCorrect answer
Inspiring
April 8, 2014

Hello Mike,

you wasn't assuming that the top left of a page in pasteborad coordinates is (0, 0). That's correct. But you assuming that the top left of a page in inner coordinates is (0, 0). And that is wrong. The page origin in inner coodinates is not (0, 0) after resizing.

Markus