Exemple #1
0
static IFontDisp *QFontToIFont(const QFont &font)
{
#if defined(Q_OS_WINCE)
    Q_UNUSED(font);
    return 0;
#else
    FONTDESC fdesc;
    memset(&fdesc, 0, sizeof(fdesc));
    fdesc.cbSizeofstruct = sizeof(FONTDESC);
    fdesc.cySize.Lo = font.pointSize() * 10000;
    fdesc.fItalic = font.italic();
    fdesc.fStrikethrough = font.strikeOut();
    fdesc.fUnderline = font.underline();
    fdesc.lpstrName = QStringToBSTR(font.family());
    fdesc.sWeight = font.weight() * 10;
    
    IFontDisp *f;
    HRESULT res = OleCreateFontIndirect(&fdesc, IID_IFontDisp, (void**)&f);
    if (res != S_OK) {
        if (f) f->Release();
        f = 0;
#if defined(QT_CHECK_STATE)
        qWarning("QFontToIFont: Failed to create IFont");
#endif
    }
    return f;
#endif
}
Exemple #2
0
LPFONT AFXAPI _AfxCreateFontFromStream(LPSTREAM pstm)
{
	BOOL bSuccess = FALSE;
	LPFONT pFont = NULL;
	LPPERSISTSTREAM pPersStm = NULL;
	CLSID clsid;

	if (SUCCEEDED(pstm->Read(&clsid, sizeof(CLSID), NULL)))
	{
		HRESULT hr;

		if (IsEqualCLSID(clsid, CLSID_StdFont) ||
			IsEqualCLSID(clsid, CLSID_StdFont_V1))
		{
			// We know this kind of font; create it using the API.
			hr = OleCreateFontIndirect((LPFONTDESC)&_fdDefault, IID_IFont,
					(LPVOID*)&pFont);
		}
		else
		{
			// Some other implementation of IFont.
			hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_IFont,
					(LPVOID*)&pFont);
		}

		if (SUCCEEDED(hr))
		{
			// Successfully created font, now get its IPersistStream interface.

			ASSERT_POINTER(pFont, IFont);

			if (SUCCEEDED(pFont->QueryInterface(IID_IPersistStream,
					(LPVOID*)&pPersStm)))
			{
				ASSERT_POINTER(pPersStm, IPersistStream);
			}
		}

		if (pPersStm != NULL)
		{
			// Load the font.

			ASSERT_POINTER(pFont, IFont);
			bSuccess = SUCCEEDED(pPersStm->Load(pstm));
			pPersStm->Release();
		}
	}

	// If we failed for any reason, clean up the font.
	if (!bSuccess && pFont != NULL)
	{
		pFont->Release();
		pFont = NULL;
	}

	return pFont;
}
Exemple #3
0
LPUNKNOWN AFXAPI _AfxCreateObjectFromStreamedPropset(LPSTREAM lpStream, REFGUID iid)
{
	LPUNKNOWN pUnk = NULL;
	CLSID clsid;

	if (_AfxGetClassIDFromStreamedPropset(&clsid, lpStream))
	{
		// Special case: we know how to create font objects
		if (IsEqualCLSID(clsid, CLSID_StdFont) ||
			IsEqualCLSID(clsid, CLSID_StdFont_V1))
		{
			if (FAILED(OleCreateFontIndirect((LPFONTDESC)&_fdDefault, iid,
					(LPVOID*)&pUnk)))
			{
				pUnk = NULL;
			}
		}
		// Special case: we know how to create picture objects
		else if (IsEqualCLSID(clsid, CLSID_StdPicture) ||
			IsEqualCLSID(clsid, CLSID_StdPicture_V1))
		{
			if (FAILED(OleCreatePictureIndirect(NULL, iid, FALSE,
					(LPVOID*)&pUnk)))
			{
				pUnk = NULL;
			}
		}
		// General case: create the object
		else if (FAILED(CoCreateInstance(clsid, NULL,
					CLSCTX_INPROC_SERVER, iid, (LPVOID*)&pUnk)))
		{
			pUnk = NULL;
		}

		if (pUnk != NULL)
		{
			if (!_AfxLoadObjectFromStreamedPropset(pUnk, lpStream))
			{
				RELEASE(pUnk);
				pUnk = NULL;
			}
		}
	}

	return pUnk;
}
IFont*
CDirect2DRM::GetDefaultFont()
{
	static FONTDESC _fontdescHeading =
	  { sizeof(FONTDESC), OLESTR("Century Gothic"), FONTSIZE( 12 ), FW_BOLD, 
     ANSI_CHARSET, FALSE, FALSE, FALSE };

	if (m_pDefFont) {
		m_pDefFont->AddRef();
		return m_pDefFont;
	} else {
		HRESULT hr = OleCreateFontIndirect( &_fontdescHeading, IID_IFont, (LPVOID*)&m_pDefFont);
		m_pDefFont->AddRef();
		//HDC hDC = GetDC(NULL);
		//hr = m_pDefFont->SetHdc(hDC);
		//ReleaseDC(NULL, hDC);
		return m_pDefFont;
	}
}
Exemple #5
0
tAmbientProperties::tAmbientProperties()
{
    //0x80000000 in OLE_COLOR indicates low byte is color index.
  m_clrBack=0x80000000+COLOR_WINDOW;
  m_clrFore=0x80000000+COLOR_WINDOWTEXT;
  m_lcid=LOCALE_USER_DEFAULT;
  m_fDesignMode = TRUE;

  m_pIOleControl = NULL;

#if 0
  {
    int cy=MulDiv(-14, LOMETRIC_PER_INCH, 72);
    //CHAPTER24MOD
    //End CHAPTER24MOD

    HFONT m_hFont=CreateFont(cy, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE
        , ANSI_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, PROOF_QUALITY
        , VARIABLE_PITCH | FF_SWISS, TEXT("Arial"));


  //m_hFont=(HFONT)GetStockObject(ANSI_VAR_FONT);

  //Need a standard font object for ambient properties

  FONTDESC    fd={sizeof(FONTDESC), L"Arial"
              , FONTSIZE(14), FW_NORMAL, DEFAULT_CHARSET
              , FALSE, FALSE, FALSE};

  OleCreateFontIndirect(
    &fd, IID_IFontDisp, (void **)&m_pIFont
    );
#endif
  m_pIFont = NULL;
}

tAmbientProperties::~tAmbientProperties()
{
  if(m_pIOleControl)
    m_pIOleControl->Release();

  if(m_pIFont)
    m_pIFont->Release();
}

void tAmbientProperties::setDesignMode(bool value, bool notify)
{
  switch(value)
  {
  case true:
    m_fDesignMode = FALSE;
    break;

  case false:
    m_fDesignMode = FALSE;
    break;
  }

  assert(m_pIOleControl);
  if(m_pIOleControl == NULL)
    return;


  // Notifica controle da mudanca

  if(notify)
    m_pIOleControl->OnAmbientPropertyChange(DISPID_AMBIENT_USERMODE);
}

OLE_COLOR tAmbientProperties::getBackColor()
{
  return m_clrBack;
}

OLE_COLOR tAmbientProperties::getForeColor()
{
  return m_clrFore;
}

bool tAmbientProperties::has_font()
{
  if(m_pIFont != NULL)
    return true;
  else
    return false;
}

IFontDisp * tAmbientProperties::getFontRef()
{
  m_pIFont->AddRef();
  return m_pIFont;
}

LCID tAmbientProperties::getLCID()
{
  return m_lcid;
}

BOOL tAmbientProperties::getDesignMode()
{
  return m_fDesignMode;
}

void tAmbientProperties::setForeColor(int red, 
                                      int green, 
                                      int blue, 
                                      bool notify)
{
  m_clrFore = blue << 16 | green << 8 | red;

  assert(m_pIOleControl);
  if(m_pIOleControl == NULL)
    return;

  if(notify)
    m_pIOleControl->
      OnAmbientPropertyChange(DISPID_AMBIENT_FORECOLOR);
}
Exemple #6
0
BOOL DispReel::LoadToken(int id, BiffReader *pbr)
{
   if (id == FID(PIID))
   {
      pbr->GetInt((int *)pbr->m_pdata);
   }
   else if (id == FID(VER1))
   {
      pbr->GetStruct(&m_d.m_v1, sizeof(Vertex2D));
   }
   else if (id == FID(VER2))
   {
      pbr->GetStruct(&m_d.m_v2, sizeof(Vertex2D));
   }
   else if (id == FID(WDTH))
   {
      pbr->GetFloat(&m_d.m_width);
   }
   else if (id == FID(HIGH))
   {
      pbr->GetFloat(&m_d.m_height);
   }
   else if (id == FID(CLRB))
   {
      pbr->GetInt(&m_d.m_backcolor);
   }
   else if (id == FID(TMON))
   {
      pbr->GetBool(&m_d.m_tdr.m_fTimerEnabled);
   }
   else if (id == FID(TMIN))
   {
      pbr->GetInt(&m_d.m_tdr.m_TimerInterval);
   }
   else if (id == FID(NAME))
   {
      pbr->GetWideString((WCHAR *)m_wzName);
   }
   else if (id == FID(TRNS))
   {
      pbr->GetBool(&m_d.m_fTransparent);
   }
   else if (id == FID(IMAG))
   {
      pbr->GetString(m_d.m_szImage);
   }
   else if (id == FID(RCNT))
   {
      float reel;
      pbr->GetFloat(&reel);
      m_d.m_reelcount = (int)reel;
   }
   else if (id == FID(RSPC))
   {
      pbr->GetFloat(&m_d.m_reelspacing);
   }
   else if (id == FID(MSTP))
   {
      pbr->GetFloat(&m_d.m_motorsteps);
   }
   else if (id == FID(SOUN))
   {
      pbr->GetString(m_d.m_szSound);
   }
   else if (id == FID(UGRD))
   {
      pbr->GetBool(&m_d.m_fUseImageGrid);
   }
   else if (id == FID(VISI))
   {
      pbr->GetBool(&m_d.m_fVisible);
   }
   else if (id == FID(GIPR))
   {
      pbr->GetInt(&m_d.m_imagesPerGridRow);
   }
   else if (id == FID(RANG))
   {
      float dig;
      pbr->GetFloat(&dig);
      m_d.m_digitrange = (int)dig;
   }
   else if (id == FID(UPTM))
   {
      pbr->GetInt(&m_d.m_updateinterval);
   }
   else if (id == FID(FONT)) //!! deprecated, only here to support loading of old tables
   {
      IFont *pIFont;
      FONTDESC fd;
      fd.cbSizeofstruct = sizeof(FONTDESC);
      fd.lpstrName = L"Times New Roman";
      fd.cySize.int64 = 260000;
      //fd.cySize.Lo = 0;
      fd.sWeight = FW_BOLD;
      fd.sCharset = 0;
      fd.fItalic = 0;
      fd.fUnderline = 0;
      fd.fStrikethrough = 0;
      OleCreateFontIndirect(&fd, IID_IFont, (void **)&pIFont);

      IPersistStream * ips;
      pIFont->QueryInterface(IID_IPersistStream, (void **)&ips);

      ips->Load(pbr->m_pistream);

      pIFont->Release();
   }
   else
   {
      ISelect::LoadToken(id, pbr);
   }
   return fTrue;
}
BOOL PickFont(HWND hWndParant, IFontDisp** ppFont)
{
	LOGFONT logfont;
	
	HFONT hFont;
	if (*ppFont != NULL)
	{
		CComPtr<IFont> spFont;
		(*ppFont)->QueryInterface(IID_IFont, (void**)&spFont);
		spFont->get_hFont(&hFont);
	}
	else
	{
		hFont = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
	}
	
	GetObject(hFont, sizeof(LOGFONT), &logfont); 
	
	CHOOSEFONT cf; 
	memset(&cf, 0, sizeof CHOOSEFONT);
	cf.hInstance = _Module.m_hInst;
	cf.lStructSize = sizeof CHOOSEFONT;
	cf.hwndOwner = hWndParant;
	cf.lpLogFont = &logfont;
	cf.lpTemplateName = "IDD_FONTDIALOG";
	cf.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_INITTOLOGFONTSTRUCT | CF_ENABLETEMPLATE;
	
	if (ChooseFont(&cf))
	{
		USES_CONVERSION;
		
		FONTDESC fd;
		fd.cbSizeofstruct = sizeof(FONTDESC);
		fd.lpstrName = T2OLE(logfont.lfFaceName);
		fd.sWeight = (short)logfont.lfWeight;
		fd.sCharset = logfont.lfCharSet;
		fd.fItalic = logfont.lfItalic;
		fd.fUnderline = logfont.lfUnderline;
		fd.fStrikethrough = logfont.lfStrikeOut;
		
		long lfHeight = logfont.lfHeight;
		if (lfHeight < 0)
			lfHeight = -lfHeight;
		
		int ppi;
		HDC hdc = ::GetDC(hWndParant);
		ppi = GetDeviceCaps(hdc, LOGPIXELSY);
		::ReleaseDC(hWndParant, hdc);
		
		fd.cySize.Lo = lfHeight * 720000 / ppi;
		fd.cySize.Hi = 0;
		
		if (*ppFont != NULL)
			(*ppFont)->Release();
		
		CComPtr<IDispatch> spFont;			
		HRESULT hr = OleCreateFontIndirect(&fd, IID_IDispatch, (void**)ppFont);
		return hr == S_OK;
	}
	
	return FALSE;
}