int pdfcrop_page(PDFDoc *doc, Catalog *catalog, SplashOutputDev *dev, int i) { PDFRectangle rect; Page *page = catalog->getPage(i); if(opt_margin){ set_media_box(doc, i, opt_margin); }else{ rect = measure_margin(doc, dev, i); set_media_box(doc, i, &rect); } if(opt_debug){ printf("page=%d, box=[", i); print_rect(page->getMediaBox()); printf("], crop=["); print_rect(&rect); printf("]\n"); } return 0; }
int main(int argc, char *argv[]) { struct rectangle rect = get_rect(); print_rect(rect); printf("The area of this rectangle: %d\n", rect_area(rect)); printf("Enter a point to check if in the rectangle:"); struct point po = get_point(); if (point_in_rect(po, rect)) { printf("The point is in the rectangle\n"); } else { printf("The point is not in the rectangle\n"); } return 0; }
void CPrint::OnPaint() { if(m_bRepaintPreview){ CWnd* item = GetDlgItem(IDC_PREVIEW_FRAME); CRect prerect; item->GetWindowRect(prerect); ScreenToClient(prerect); int obase = m_Calculator->m_base; m_Calculator->m_base = 10; UpdateData(); CDC print_dc; print_dc.Attach(m_PrintDlg.GetPrinterDC()); // Attach a printer DC CPaintDC dc(this); // device context for painting CPoint ul(prerect.left + 10, prerect.top + 19); CRect print_rect(0,0, print_dc.GetDeviceCaps(HORZRES), print_dc.GetDeviceCaps(VERTRES)); CRect window_rect(0,0,prerect.Width() - 20, prerect.Height() - 25); double scale_factor; TRACE("print_rect.Width=%d print_rect.Height=%d\n", print_rect.Width(), print_rect.Height()); if((double(print_rect.Width())/double(print_rect.Height())) > (double(window_rect.Width())/double(window_rect.Height()))) scale_factor = double(window_rect.Width()) / double(print_rect.Width()); else scale_factor = double(window_rect.Height()) / double(print_rect.Height()); CPoint start; start.x = ul.x + (double(window_rect.Width() - (print_rect.Width() * scale_factor)) / 2.0); start.y = ul.y + (double(window_rect.Height() - (print_rect.Height() * scale_factor)) / 2.0); //////////// DRAW PAPER CBrush brush(RGB(255,255,255)), *pOldBrush; pOldBrush = dc.SelectObject(&brush); CPen penBlack; penBlack.CreatePen(PS_SOLID, 0, RGB(0,0,0)); CPen* pOldPen = dc.SelectObject(&penBlack); dc.Rectangle(start.x - 3, start.y - 3, start.x + (print_rect.Width() * scale_factor) + 3, start.y + (print_rect.Height() * scale_factor) + 3); dc.SelectObject(pOldPen); //////////// END DRAW PAPER //////////// Calculate width and height long double w, h; if(m_iPageSize == 1){ double scale; if((double(print_rect.Width()) / double(m_graph_width)) > (double(print_rect.Height()) / double(m_graph_height))) scale = (double(print_rect.Height()) / 2.0) / double(m_graph_height); else scale = (double(print_rect.Width()) / 2.0) / double(m_graph_width); h = (double(m_graph_height)/double(print_dc.GetDeviceCaps(LOGPIXELSY))) * scale; w = (double(m_graph_width)/double(print_dc.GetDeviceCaps(LOGPIXELSX))) * scale; } else if(m_iPageSize == 0){ w = double(print_rect.Width()) / double(print_dc.GetDeviceCaps(LOGPIXELSX)); h = double(print_rect.Height()) / double(print_dc.GetDeviceCaps(LOGPIXELSY)); } else{ m_Calculator->StringToDecimal(m_sWidth, 10, w); m_Calculator->StringToDecimal(m_sHeight, 10, h); w = m_Calculator->abs(w); h = m_Calculator->abs(h); // convert width if(m_sWUnits == "cm") w *= 0.39370078740157; // convert height if(m_sHUnits == "cm") h *= 0.39370078740157; } // I now have desired width and height in inches CPoint gstart(start.x, start.y); double max_h((double(print_rect.Height()) / double(print_dc.GetDeviceCaps(LOGPIXELSY)))); double max_w((double(print_rect.Width()) / double(print_dc.GetDeviceCaps(LOGPIXELSX)))); // resize max height based on printing options if(m_bTitleOn){ max_h -= (0.25 + 0.125); gstart.y += ((0.25 + 0.125) * print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor); } if(m_bEquations) max_h -= (1.5 + 0.125); // error check for desired size too large too large if(w > (max_w + 0.0001)){ w = max_w; m_Calculator->DecimalToString(m_sWidth, w); if(m_iPageSize == 2) SetDimensionsW(w); } if(h > (max_h + 0.0001)){ h = max_h; m_Calculator->DecimalToString(m_sHeight, h); if(m_iPageSize == 2) SetDimensionsH(h); } // now convert inches into device units (ie device pixels) w *= print_dc.GetDeviceCaps(LOGPIXELSX) * scale_factor; // scale w for window h *= print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor; // scale h for window //////////// END Calculate width and height //////////// Draw Graph Rectangle CBrush gray(RGB(128,128,128)); dc.SelectObject(&gray); if(m_bCenter){ gstart.x += ((print_rect.Width() * scale_factor) / 2.0) - (w / 2.0); double th(h); if(m_bTitleOn) th += ((0.25 + 0.125) * print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor); if(m_bEquations) th += ((1.5 + 0.125) * print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor); gstart.y += (double(print_rect.Height() * scale_factor) / 2.0) - (double(th) / 2.0); } dc.Rectangle(gstart.x, gstart.y, gstart.x + w, gstart.y + h); //////////// END Draw Graph Rectangle if(m_bEquations){ //////////// Draw Equations List CPoint estart(gstart.x, gstart.y + h +(0.125 * print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor)); CPoint eend(gstart.x + w, gstart.y + h + (1.625 * print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor)); int ew(w); if(ew < (5 * print_dc.GetDeviceCaps(LOGPIXELSX) * scale_factor)) // check for min eqs list size ew = (5 * print_dc.GetDeviceCaps(LOGPIXELSX) * scale_factor); if(ew > (max_w * print_dc.GetDeviceCaps(LOGPIXELSX) * scale_factor)) ew = max_w; if((eend.y - estart.y) > (max_h * print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor)) eend.y = estart.y + max_h; estart.x = (gstart.x + (double(w) / 2.0)) - (double(ew) / 2.0); if(estart.x < start.x) estart.x = start.x; eend.x = estart.x + ew; dc.SelectObject(&brush); dc.Rectangle(estart.x, estart.y, eend.x, eend.y); //////////// END Draw Equations List } if(m_bTitleOn){ //////////// Draw Title Rectangle dc.SelectObject(&brush); dc.Rectangle(start.x, start.y, start.x + (print_rect.Width() * scale_factor), start.y + (0.25 * print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor)); //////////// END Draw Title Rectangle } dc.SelectObject(pOldBrush); print_dc.Detach(); UpdateData(true); m_Calculator->m_base = obase; } }