Exemplo n.º 1
0
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);
	}
}
Exemplo n.º 2
0
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
}