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; } } }
void CFontPreviewWnd::OnPaint() { CPaintDC dc(this); // device context for painting // Draw the background CRect rct; GetClientRect(rct); dc.FillSolidRect(&rct, RGB(255, 255, 255)); // Get the active view CMDIFrameWnd *pFrame = (CMDIFrameWnd*)GET_PMWAPP()->m_pMainWnd; CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); CPmwView *pView = (CPmwView *)pChild->GetActiveView(); // Find the current document CPmwDoc* pDoc = (CPmwDoc*)(pChild->GetActiveDocument()); ASSERT(pDoc != NULL); // Get the database PMGDatabasePtr database = pDoc->get_database(); // Get the current style CTextStyle Style(database); CTxp* pTxp = pView->GetTxp(); Style = pTxp->Style(); // If text color is white, make it black so we can see it FillFormatV1& Fill = Style.Fill(); if (Fill.m_ForegroundColor == COLOR_WHITE) { Fill.m_ForegroundColor = COLOR_BLACK; } // Get the entry for this face. FaceEntry* entry; int face_to_use = m_nFontID; int font_number = -1; if ((entry = typeface_server.face_list.get_face(face_to_use)) != NULL) { int nVariation = 0; if (Style.Bold()) { nVariation |= FONT_STYLE_Bold; } if (Style.Italic()) { nVariation |= FONT_STYLE_Italic; } VARIATION_TYPE vtype = entry->get_variation_type(nVariation); if (vtype == VARIATION_TYPE_VIRTUAL || vtype == VARIATION_TYPE_REGISTRATION) { // We want to use the preview font for "virtual" (PMW.FFL) fonts. Check if // the font has an entry in the preview font. font_number = entry->get_preview_font_number(nVariation); if (font_number != -1) { // Set the font number back to -1 in case we fail. It will // be reloaded if we can sucessfully use the preview font. font_number = -1; // We want to use the font preview. Try to switch to the preview font. PCSTR pn = typeface_server.preview_face_name(); if (pn != NULL) { int found_face; if ((found_face = typeface_server.find_face(pn, FALSE)) != -1) { face_to_use = found_face; font_number = entry->get_preview_font_number(nVariation); } } } } } // Get a database record for this face. // This will be a 'temporary' reference which we must free. PMGFontServer *pFontServer = (PMGFontServer*)pDoc->get_font_server(); DB_RECORD_NUMBER f_record = pFontServer->font_face_to_record(face_to_use); // Set the face in the style. The style gets its own reference. Style.Font(f_record); // Default to 36 point. Style.BaseSize(MakeFixed(36)); Style.Size(Style.BaseSize()); Style.UpdateFontMetrics(); // Free our temp reference. database->free_font_record(f_record, TRUE); // Build the redisplay context. RedisplayContext rc; rc.destination_hdc = dc.m_hDC; rc.hwnd = m_hWnd; rc.scaled_source_x0 = rc.scaled_source_y0 = 0; rc.destination_rect = rct; rc.destination_x0 = 0; rc.destination_y0 = 0; rc.x_resolution = GetDeviceCaps(dc.m_hDC, LOGPIXELSX); rc.y_resolution = GetDeviceCaps(dc.m_hDC, LOGPIXELSY); //rc.outline_gamma_curve = rc.bitmap_gamma_curve = screen_gamma_curve; //rc.set_check_interrupt(standard_check_interrupt, (void*)&rc); rc.terminate_interrupts = TRUE; rc.clip_rect = rct; // Initialize the redisplay context so we can use it rc.set_info(dc.m_hDC); rc.screen_to_pbox(&rct, &rc.source_pbox); // Create the frame object now. FRAMEOBJ_CREATE_STRUCT fcs; fcs.alignment = ALIGN_center; fcs.vert_alignment = ALIGN_middle; fcs.bound = rc.source_pbox; CFrameObject* pObject; if ((pObject = database->create_frame_object(&fcs)) != NULL) { // This object is not on the page! pObject->OnPage(FALSE); // Nor is it selected! pObject->remove_select_flags(SELECT_FLAG_boundary); // Prepare to add some text. CTxp Txp(database); CHARACTER Text[4]; if (font_number == -1) { Text[0] = 'T'; Text[1] = 'y'; Text[2] = 'p'; Text[3] = 'e'; } else { // We substituted the preview font int ch_base = font_number*4 + '!'; Text[0] = ch_base++; Text[1] = ch_base++; Text[2] = ch_base++; Text[3] = ch_base++; } // Stick in some text Txp.Init(pObject, 0); Txp.SetHorizontalAlignment(ALIGN_center); Txp.Style(Style); Txp.InsertText(Text, 4); // Select our palette in. CPalette* pOldPalette = dc.SelectPalette(pOurPal, FALSE); if (pOldPalette != NULL) { dc.RealizePalette(); } // And draw the object! UpdateStatePtr ustate; if ((ustate = pObject->update(&rc, &fcs.bound, &rct, NULL, REFRESH_ALL)) != NULL) { // See what happened switch (ustate->type) { case UPDATE_TYPE_Interrupted: { // This should not happen delete ustate; // Fall through to... } case UPDATE_TYPE_Terminated: { // Try again later InvalidateRect(&rct, FALSE); break; } default: { break; } } } pObject->destroy(); // Remove from the document. delete pObject; // Select our palette back out. if (pOldPalette != NULL) { dc.SelectPalette(pOldPalette, FALSE); } } // Do not call CBarMRUCombo::OnPaint() for painting messages }