static void CreateFrame(CPmwView* pView, LPCSTR pszText, const PBOX& Bound, ALIGN_TYPE nHAlign, VERT_ALIGN_TYPE nVAlign) { CPmwDoc* pDoc = pView->GetDocument(); PMGDatabase* pDatabase = pDoc->get_database(); FRAMEOBJ_CREATE_STRUCT fcs; fcs.bound = Bound; fcs.alignment = nHAlign; fcs.vert_alignment = nVAlign; fcs.flags = 0; fcs.pStyle = NULL; CFrameObject* pFrame = pDoc->create_frame_object(&fcs); if (pFrame != NULL) { pDoc->append_object(pFrame); CTextStyle Style(pDatabase); Style.SetDefault(); // Set the face to "Geneva". int nFace = typeface_server.find_face("Geneva", FALSE); if (nFace != -1) { PMGFontServer* pFontServer = (PMGFontServer*)pDoc->get_font_server(); DB_RECORD_NUMBER lFace = pFontServer->font_face_to_record(nFace); if (lFace != 0) { Style.Font(lFace); pDatabase->free_font_record(lFace, TRUE); } } Style.Size(MakeFixed(150)); Style.BaseSize(MakeFixed(150)); Style.UpdateFontMetrics(); CTxp Txp(pDatabase); Txp.Init(pFrame, 0); Txp.SetHorizontalAlignment(fcs.alignment); Txp.Style(Style); Txp.InsertString(pszText); } }
SHORT CCatalogView::OnPrintDocument(PrintContext &pc, int32 aCurrentDocument, int32 aNumDocuments) { CPmwDoc *pDoc = GetDocument(); SHORT bError = FALSE; SHORT x, y; PCOORD grid_width, grid_height, step_width, step_height, text_height, new_x; PBOX pbox; int32 current_page, num_pages; #ifdef SPECIAL_CATALOG PCOORD x0 = 0, y0 = (PAGE_RESOLUTION*3)/4; #endif CCatalogPrint *pdlg = (CCatalogPrint *)pc.m_pPD; #ifdef OLD_CATALOG_STYLE CString csNameBuffer; #endif /* Compute the size of the grid and the step. */ PPNT dims = pDoc->get_dimensions(); PMGDatabasePtr const database = pDoc->get_database(); CTextStyle Style(database); #ifdef CATALOG_BACKGROUND PATTERN_CREATE_STRUCT pcs; pcs.bound.x0 = 0; pcs.bound.y0 = 0; pcs.bound.x1 = dims.x; pcs.bound.y1 = dims.y; pcs.pattern = 0; pcs.color = COLOR_WHITE; pcs.bcolor = MAKE_COLOR(0, 0, 0, 32); #endif #ifdef SPECIAL_CATALOG dims.x -= x0; dims.y -= y0; SHORT const across = 10; SHORT const down = 5; #else SHORT const across = pdlg->m_x_count; SHORT const down = pdlg->m_y_count; #endif grid_width = dims.x/across; grid_height = dims.y/down; step_width = scale_pcoord(grid_width, 9, 10); Style.SetDefault(); SHORT base_size; #ifdef DOUBLE_NAMES step_height = scale_pcoord(grid_height, 7, 10); text_height = (grid_height - step_height)/2; base_size = (SHORT)scale_pcoord(text_height, (72*6)/10, PAGE_RESOLUTION); #else step_height = scale_pcoord(grid_height, 9, 10); text_height = grid_height - step_height; base_size = (SHORT)scale_pcoord(text_height, (72*2)/3, PAGE_RESOLUTION); #endif /* Set the text style. */ if (base_size > 12) { base_size = 12; } Style.Size(MakeFixed(base_size)); Style.BaseSize(MakeFixed(base_size)); #ifdef DOUBLE_NAMES Style.Bold(TRUE); #endif Style.UpdateFontMetrics(); /* Figure out number of pages we will print. */ num_pages = #ifdef SPACE_ON_FIRST across + #endif m_picture_list.GetSize(); { SHORT n; n = across * down; num_pages = (num_pages + n - 1) / n; } current_page = 0; /* Run through all the graphics. */ ObjectListPtr list = pDoc->object_list(); int nMaxNames = m_picture_list.GetSize(); BOOL broken; int nEntry; for (broken = FALSE, nEntry = 0; !broken && nEntry < nMaxNames ;) { // Tell the user what we're doing. printer_update_name(NULL, GET_PMWAPP()->GetResourceStringPointer (IDS_BUILDING_PAGE), (VOIDPTR)&pc); // Make sure the current page is blank. list->destroy_objects(); // Build the next page. BeginWaitCursor(); #ifdef CATALOG_BACKGROUND PatternObjectPtr patobj; if ((patobj = database->create_pattern_object(&pcs)) != NULL) { pDoc->append_object(patobj); } #endif #ifdef SPECIAL_CATALOG for (pbox.y0 = y0, y = 0; #else for (pbox.y0 = 0, y = 0; #endif y < down && !broken; y++, pbox.y0 += grid_height) { #ifdef SPACE_ON_FIRST if (current_page == 0 && y == 0) { continue; } #endif pbox.y1 = pbox.y0 + step_height; #ifdef SPECIAL_CATALOG for (pbox.x0 = x0, x = 0; #else for (pbox.x0 = 0, x = 0; #endif x < across; x++, pbox.x0 += grid_width, nEntry++) { CFrameObject* pFrame; PPNT p; // Make sure we are on a good node. if (nEntry == nMaxNames) { /* All done! */ y = down; break; } CString strName = m_picture_list.GetAt(nEntry); /* Show the name. */ // multi_context.current_name = node->name; /* We have a selected node. Make a graphic for it. */ pbox.x1 = pbox.x0 + step_width; /* Create the graphic object. */ #ifdef OLD_CATALOG_STYLE csNameBuffer = m_chosen_dir; csNameBuffer += strName; #endif GraphicObjectPtr object; GRAPHIC_CREATE_STRUCT gcs; #ifdef OLD_CATALOG_STYLE gcs.m_csFileName = csNameBuffer; #else gcs.m_csFileName = strName; #endif if ((object = database->create_graphic_object(&gcs)) != NULL) { /* Get the size of the graphic. */ if (object->original_dims(&p)) { pDoc->append_object(object); dims.x = (PCOORD)step_width; dims.y = (PCOORD)step_height; /* Fit the graphic to its box. */ if ((new_x = scale_pcoord(dims.y, p.x, p.y)) > dims.x) { dims.y = scale_pcoord(dims.x, p.y, p.x); } else { dims.x = new_x; } /* Set the bound. */ PBOX bound; bound.x0 = (pbox.x0 + pbox.x1 - dims.x)/2; bound.x1 = bound.x0 + dims.x; bound.y0 = (pbox.y0 + pbox.y1 - dims.y)/2; bound.y1 = bound.y0 + dims.y; object->set_bound(bound); object->calc(); } else { delete object; object = NULL; } } /* Add a text frame for the name. */ FRAMEOBJ_CREATE_STRUCT fcs; LPCSTR text = strName; fcs.bound.x0 = pbox.x0; fcs.bound.x1 = pbox.x1; fcs.bound.y0 = pbox.y1; fcs.alignment = ALIGN_center; fcs.vert_alignment = ALIGN_top; // fcs.text = NULL; fcs.flags = 0; fcs.pStyle = NULL; #ifdef SPECIAL_CATALOG CHAR buffer[100]; LPCSTR ptr; if ((ptr = strrchr(text, '\\')) == NULL) { ptr = text; } else { /* Move off of '\'. */ ptr++; } strcpy(buffer, ptr); LPSTR foop; if ((foop = strrchr(buffer, '.')) != NULL) { /* Remove extension. */ *foop = '\0'; } fcs.bound.y1 = fcs.bound.y0+text_height; text = buffer; #elif defined(DOUBLE_NAMES) fcs.bound.y1 = fcs.bound.y0+text_height*2; CHAR name[64]; CHAR buffer[100]; LPCSTR ptr; if ((ptr = strrchr(text, '\\')) == NULL) { ptr = text; } else { /* Move off of '\'. */ ptr++; } BOOL blanket = FALSE; /* porpoise-ly (just for pun) */ if (object == NULL) { blanket = TRUE; } else { object->get_name(name, sizeof(name), -1); if (stricmp(name, ptr) == 0) { blanket = TRUE; strcpy(name, " "); } } if (blanket) { /* Blank it. */ strcpy(name, " "); } // sprintf(buffer, "%s\n%s", name, p); strcpy(buffer, name); strcat(buffer, "\n"); strcat(buffer, ptr); text = buffer; #else fcs.bound.y1 = fcs.bound.y0+text_height; #endif if ((pFrame = pDoc->create_frame_object(&fcs)) == NULL) { broken = TRUE; break; } int nCharacters = strlen(text); if (nCharacters != 0) { CTxp Txp(database); Txp.Init(pFrame, 0); Txp.SetHorizontalAlignment(fcs.alignment); Txp.Style(Style); TRY { CHARACTER* pText = new CHARACTER[nCharacters]; for (int n = 0; n < nCharacters; n++) { pText[n] = (CHARACTER)text[n]; } #ifdef DOUBLE_NAMES // First line is name + CR... int nLine1 = strlen(name)+1; // ...second line is the rest. int nLine2 = nCharacters - nLine1; // Insert line 1. Txp.InsertText(pText, nLine1); // Compute style for line 2: // no bold, and 8/10 the size. Txp.Style().Bold(FALSE); CFixed lSize = Txp.Style().BaseSize(); lSize = MulDivFixed(lSize, MakeFixed(8), MakeFixed(10)); Txp.Style().BaseSize(lSize); Txp.Style().Size(lSize); Txp.Style().UpdateFontMetrics(); // Insert line 2. Txp.InsertText(pText+nLine1, nLine2); #else Txp.InsertText(pText, nCharacters); #endif delete [] pText; } END_TRY } pDoc->append_object(pFrame); } } EndWaitCursor(); /* See if we broke! */ if (broken) { break; } /* Print the page. */ if (list->count() != 0) { /* We have objects! Print them. */ ++current_page; if (bError = CPmwView::OnPrintDocument(pc, current_page, num_pages)) { break; } } }