page_handler.cpp

来自「ncbi源码」· C++ 代码 · 共 774 行 · 第 1/2 页

CPP
774
字号
        }        break;    }    link["Rect"] = new CPdfObj("[" + _x1 + " " + _y1 + " " + _x2 + " " + _y2 + "]");    link["Border"] = new CPdfObj("[3 3 2]");    link["C"] = new CPdfObj("[0.416 0.549 0.792]");    link["H"] = new CPdfName("P");    CRef<CPdfArray> dest(new CPdfArray());    const CRef<CPanel> p = m_PanelGrid->GetPanel(panel_num);    dest->GetArray().push_back(CRef<CPdfObj>(new CPdfIndirectObj(p->m_Panel)));    dest->GetArray().push_back(CRef<CPdfObj>(new CPdfName("Fit")));    link["Dest"] = dest;    annots->GetArray().push_back(CRef<CPdfObj>(link_annot));    obj << CPdfObj("Q") << pdfbrk;    return annots;}void CPageHandler::x_DrawTriangle(CPdfObject& obj,                                  TPdfUnit x,                                  TPdfUnit y,                                  TPdfUnit width,                                  TPdfUnit height                                 ) const{    const TPdfUnit w = width / 2;    obj << CPdfNumber(x - w) << ' ' << CPdfNumber(y) << " m ";    obj << CPdfNumber(x) << ' ' << CPdfNumber(y + int(height)) << " l ";    obj << CPdfNumber(x + w) << ' ' << CPdfNumber(y) << " l h f" << pdfbrk;}CPageHandler::TPdfObjectRef CPageHandler::x_CreatePageClipObject(void){    TPdfObjectRef clip_obj(new CPdfObject(m_ObjIdGenerator->NextId()));    CPdfObject& clip = *clip_obj;    // margin between actual margin and printing marks    const TPdfUnit pmm = 1;    // create printer's marks, page alignment etc    const TPdfUnit L = m_Options->GetMarginLeft() - pmm;    const TPdfUnit B = m_Options->GetMarginBottom() - pmm;    const TPdfUnit R = m_Options->GetMediaWidth() - m_Options->GetMarginLeft() + pmm;    const TPdfUnit T = m_Options->GetMediaHeight() - m_Options->GetMarginTop() + pmm;    clip << L << ' ' << B << " m ";    clip << R << ' ' << B << " l ";    clip << R << ' ' << T << " l ";    clip << L << ' ' << T << " l W n" << pdfbrk;    return clip_obj;}CPageHandler::TPdfObjectRef CPageHandler::x_CreateContentXForm(void){    TPdfObjectRef xform_obj(new CPdfObject(m_ObjIdGenerator->NextId()));    CPdfObject& xform = *xform_obj;    //    // scale and translate the coordinate system based on the size of    // the page content    //    const CPageBuffers::TOffset docsize = m_PageBuffers->GetPageSize();    const pair<float, float> scale = x_GetPageScaling(docsize.first, docsize.second);    xform << scale.first << " 0 0 " << scale.second << " 0 0 cm" << pdfbrk;    const CBBox<3>& bbox = m_PageBuffers->GetBoundingBox();    const float x_off = bbox.GetNthRange(0).first;    const float y_off = bbox.GetNthRange(1).first;    xform << "1 0 0 1 " << -x_off << ' ' << -y_off << " cm" << pdfbrk;    return xform_obj;}CPageHandler::TPdfObjectRef CPageHandler::x_CreatePageXForm(const CRef<CPanel>& panel){    // translate page according to offset    TPdfObjectRef xform_obj(new CPdfObject(m_ObjIdGenerator->NextId()));    CPdfObject& xform = *xform_obj;    const TOffset offset = x_GetPanelOffset(panel);    xform << "1 0 0 1 " << offset.first << ' ' << offset.second << " cm" << pdfbrk;    return xform_obj;}//// GetPanelOffset() - given dimensions in PDF (default user space)//                    coordinates, return page offsets in that coordinate//                    system given horizontal and vertical alignments.//// The horizontal/vertical factors specify the number of pages// by which to offset this panel//CPageHandler::TOffset CPageHandler::x_GetPanelOffset(const CRef<CPanel>& panel) const{    const TAlignment& halign = panel->m_HAlign;    const TAlignment& valign = panel->m_VAlign;    const unsigned int pg_wide = m_Options->GetPagesWide();    const unsigned int pg_tall = m_Options->GetPagesTall();    const TPdfUnit page_w = m_Options->GetPageTrimWidth();    const TPdfUnit page_h = m_Options->GetPageTrimHeight();    TSize docsize = x_GetScaledPageSize();    const TPdfUnit fullpg_wide = pg_wide < 3 ? 0 : pg_wide - 2;    const TPdfUnit fullpg_w = fullpg_wide * page_w;    if (halign == CPrintOptions::eCenter) {        docsize.first = page_w;    }    else {        docsize.first = (docsize.first - fullpg_w) / 2;    }    const TPdfUnit fullpg_tall = pg_tall < 3 ? 0 : pg_tall - 2;    const TPdfUnit fullpg_h = fullpg_tall * page_h;    if (valign == CPrintOptions::eMiddle) {        docsize.second = page_h;    }    else {        docsize.second = (docsize.second - fullpg_h) / 2;    }    //int h_offset = page_w * -panel->m_HPageOffset + m_Options->GetMarginLeft();    //int v_offset = page_h * -panel->m_VPageOffset + m_Options->GetMarginBottom();    TPdfUnit h_offset = -fullpg_w + m_Options->GetMarginLeft();    TPdfUnit v_offset = -fullpg_h + m_Options->GetMarginBottom();    switch (halign) {    case CPrintOptions::eLeft:        //h_offset += docsize.first - page_w;        break;    case CPrintOptions::eCenter:        h_offset += (page_w - docsize.first) / 2;        break;    case CPrintOptions::eRight:        h_offset += page_w - docsize.first;        break;    default:        break;    }    switch (valign) {    case CPrintOptions::eTop:        v_offset += page_h - docsize.second;        break;    case CPrintOptions::eMiddle:        v_offset += (page_h - docsize.second) / 2;        break;    case CPrintOptions::eBottom:        //v_offset += docsize.second - page_h;        break;    default:        break;    }    return make_pair(h_offset, v_offset);}//// x_GetPageScaling() - scale the dimensions in the user's coordinate system to//                      dimensions in PDF (default user space)//pair<float, float> CPageHandler::x_GetPageScaling(TPdfUnit w,                                                  TPdfUnit h,                                                  bool keepAspect                                                 ) const{    const TPdfUnit page_w = m_Options->GetPageTrimWidth();    const TPdfUnit page_h = m_Options->GetPageTrimHeight();    const TPdfUnit total_w = page_w * m_Options->GetPagesWide();    const TPdfUnit total_h = page_h * m_Options->GetPagesTall();    const float scale_w = float(total_w) / w;    const float scale_h = float(total_h) / h;    if (keepAspect) {        const float scale = scale_w < scale_h ? scale_w : scale_h;        return make_pair(scale, scale);    }    return make_pair(scale_w, scale_h);}void CPageHandler::SetContent(const TPdfObjectRef& content){    m_Content = content;}void CPageHandler::WritePageTree(const CRef<CPdfDictionary>& pagedict){    const_cast<CPageHandler*>(this)->x_Update(pagedict);    m_ObjWriter->WriteObject(m_PageTreeRootObj);}const CPageHandler::TSize CPageHandler::x_GetScaledPageSize(void) const{    const CPageBuffers::TOffset sz = m_PageBuffers->GetPageSize();    const pair<float, float> scale(x_GetPageScaling(sz.first, sz.second));    return TSize(scale.first * sz.first,                 scale.second * sz.second                );}unsigned int CPageHandler::WritePages(void){    //    // write the content object    //    m_ObjWriter->WriteObject(m_Content);    //    // write the header/footer object    //    TPdfObjectRef headfoot_obj = x_CreateHeaderFooter();    if (headfoot_obj.GetPointer()) {        m_StdContents.push_back(headfoot_obj);        m_ObjWriter->WriteObject(headfoot_obj);    }    //    // create the clip/crop object    //    m_Clip = x_CreatePageClipObject();    m_ObjWriter->WriteObject(m_Clip);    //    // create the content transform object    //    m_ContentPagesXForm = x_CreateContentXForm();    m_ObjWriter->WriteObject(m_ContentPagesXForm);    //    // generate and output the content pages    //    unsigned int panel_num = 1;    const unsigned int pg_wide = m_Options->GetPagesWide();    const unsigned int pg_tall = m_Options->GetPagesTall();    for (unsigned int row = 0; row < pg_tall; ++row) {        //const TAlignment valign = m_PanelGrid->GetVAlign(row);        for (unsigned int col = 0; col < pg_wide; ++col, ++panel_num) {            //const TAlignment halign = m_PanelGrid->GetHAlign(col);            const CRef<CPanel> panel = m_PanelGrid->GetPanel(col, row);            //            // create printer's marks            //            TPdfObjectRef printers_marks = x_CreatePrintersMarks(panel);            m_ObjWriter->WriteObject(printers_marks);            //            // offset the page (alignment)            //            TPdfObjectRef page_xform = x_CreatePageXForm(panel);            m_ObjWriter->WriteObject(page_xform);            //            // set the page contents            //            CRef<CPdfArray> contents(new CPdfArray());            CPdfArray::TArray& carr = contents->GetArray();            ITERATE(vector<TPdfObjectRef>, it, m_StdContents) {                carr.push_back(CRef<CPdfObj>(new CPdfIndirectObj(*it)));            }            carr.push_back(CRef<CPdfObj>(new CPdfIndirectObj(printers_marks)));            carr.push_back(CRef<CPdfObj>(new CPdfIndirectObj(m_Clip)));            carr.push_back(CRef<CPdfObj>(new CPdfIndirectObj(page_xform)));            carr.push_back(CRef<CPdfObj>(new CPdfIndirectObj(m_ContentPagesXForm)));            carr.push_back(CRef<CPdfObj>(new CPdfIndirectObj(m_Content)));            x_CreatePage(panel->m_Panel, contents);        }    }    return m_PanelGrid->GetNumPanels();}void CPageHandler::x_CreatePage(TPdfObjectRef page, CRef<CPdfArray>& contents){    // create page object    CPdfObject& pageobj = *page;    m_Pages.push_back(page);    pageobj["Type"] = new CPdfName("Page");    pageobj["Parent"] = new CPdfIndirectObj(m_PageTreeRootObj);    pageobj["Contents"] = contents;    //    // output the page    //    m_ObjWriter->WriteObject(page);}END_NCBI_SCOPE/* * =========================================================================== * $Log: page_handler.cpp,v $ * Revision 1000.1  2004/06/01 21:03:36  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.17 * * Revision 1.17  2004/05/21 22:27:50  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.16  2003/10/14 15:53:13  meric * Add page header/footer object only if a header or footer is provided * * Revision 1.15  2003/08/15 17:02:15  meric * Updates include paths for print-related files from gui/utils to gui/print * * Revision 1.14  2003/06/25 18:02:51  meric * Source rearrangement: move "private" headers into the src/ tree * * Revision 1.13  2003/06/24 22:37:44  meric * renamed struct Neighbours to struct SNeighbours, removed TNeighbours typedef * * Revision 1.12  2003/06/24 21:07:07  meric * Only add Annots entry to Page object if there is at least one annotation * * Revision 1.11  2003/06/24 18:11:12  meric * Further conversions from unsigned int -> CUnit::TPdfUnit * * Revision 1.10  2003/06/24 17:27:03  meric * Use CUnit::TPdfUnit * * Revision 1.9  2003/06/24 15:53:25  meric * Added x_GetPageScaling() and x_GetPanelOffset(), from CPrintOptions * Added x_GetPanelOffset(), x_DrawPanelLink() and misc functions * Improved printer's marks to include hyperlinked references to neighbouring * panels and corner crop marks * * Revision 1.8  2003/06/18 17:25:38  meric * Final phase of print reorg: remove dependence on gui/opengl and OpenGL * * Revision 1.7  2003/06/18 16:40:33  meric * First phase of print reorg: remove dependence on gui/opengl and OpenGL * except for class COpenGLPrintBuffer * * Revision 1.6  2003/06/17 18:58:08  meric * Remove inline qualifier for x_GetScaledPageSize() * * Revision 1.5  2003/06/16 21:16:52  meric * Added multi-page support * * Revision 1.4  2003/06/16 19:16:33  meric * Fixed member initialization order in c'tor to match declaration order * * Revision 1.3  2003/06/16 15:59:11  dicuccio * Work-in-progress: everything compiles, still much reorganization to be done. * Moved generic functionality out of opengl/print/ and into gui/utils (print * options, print dialogs, etc.).  Removed interactive state from CGlCanvas. * Added hook in CView for opening standard print dialog, and for generic print * handling.  Restored log for glcanvas.cpp * * Revision 1.2  2003/06/16 12:44:52  dicuccio * Clean-up after initial commit * * Revision 1.1  2003 / 06 / 13 18:13:56  meric * Initial version * * * =========================================================================== */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?