home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / nsfont.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.1 KB  |  192 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef __NSFONT_H__
  20. #define __NSFONT_H__
  21.  
  22. #include "nf.h"
  23.  
  24. /*
  25.  * Uses:
  26.  *    FontBrokerInterfaces (nffbc, nffbp, nffbu)
  27.  */
  28. #include "Mnffbc.h"
  29. #include "Mnffbp.h"
  30. #include "Mnffbu.h"
  31. #include "Mnffp.h"
  32.  
  33. #include "Mnffmi.h"        // for nffmi_GetValue() nffmi_release()
  34.  
  35. #include "Mwinfp.h"     // in ns\modules\libfont\src\_jmc  
  36. #include <windows.h>        // for CDC
  37.  
  38. enum FontModuleReturnCode {
  39.     FONTERR_OK   = 0 ,
  40.     FONTERR_ConvertDCFailed,
  41.     FONTERR_CreateFontMatchInfoFailed,
  42.     FONTERR_CreateObjectFail,
  43.     FONTERR_GetInterfacesFail,
  44.     FONTERR_nffbc_LookupFontFailed,
  45.     FONTERR_NotInitiated,
  46.     FONTERR_RegisterFontDisplayerFail,
  47.     
  48. };
  49.     
  50.  
  51.  
  52. class CNetscapeFontModule : public CObject
  53. {
  54. public :
  55.     CNetscapeFontModule::CNetscapeFontModule();
  56.     CNetscapeFontModule::~CNetscapeFontModule();
  57.  
  58.     // must be called first
  59.     int            CNetscapeFontModule::InitFontModule();  
  60.  
  61.     // error handling 
  62.     int         getLastError() { return(m_lastError); }
  63.  
  64.     // general service functions
  65.     struct nfrc        *CNetscapeFontModule::convertDC( HDC hDC );
  66.     struct nffbu    *getBrokerUtilityInterface() { return( m_pFontBrokerUtilityInterface ); }
  67.     struct nffbc    *getFontBrokerConsumerInterface(){ return(m_FontBrokerConsumerInterface); }
  68.  
  69.     struct nffmi    **CNetscapeFontModule::CreateFMIList(HDC hDC );
  70.     int                CNetscapeFontModule::FreeFMIList( struct nffmi ** fmiList);
  71.  
  72.     int CNetscapeFontModule::releaseAllFontResource(MWContext *pContext);
  73.     int CNetscapeFontModule::LookupFailed(MWContext *pContext, struct nfrc *prc, struct nffmi * pfmi);
  74.     int    CNetscapeFontModule::WebfontsNeedReload( MWContext *pContext );
  75.  
  76.     
  77. private :
  78.     int createObjects();
  79.     int getInterfaces();
  80.     int CNetscapeFontModule::registerFontDisplayer();
  81.     int CNetscapeFontModule::releaseDisplayer();
  82.     int    CNetscapeFontModule::UpdateWorkingRC( HDC hDC );
  83.  
  84.     int    m_fontModuleStatus;
  85.     int    m_lastError;
  86.     enum fontModuleStatus {
  87.         FMSTATUS_NULL = 0,
  88.         FMSTATUS_IntialOK,
  89.     };
  90.  
  91.     // helpers
  92. public :
  93.     struct nffmi* CNetscapeFontModule::createFMIfromLOGFONTWithAttr( LOGFONT *pLogFont, 
  94.                   int pixelPerPoint, int extraAttributes );
  95.  
  96.     // the following 3 helpers are identical as in producers\win\winfp.c 
  97.     char * CNetscapeFontModule::convertToFmiCharset( BYTE charSetID );  // used to be LOGFONT *pLogFont
  98.     int CNetscapeFontModule::convertToFmiStyle( LOGFONT *pLogFont );
  99.     int CNetscapeFontModule::convertToFmiPitch( LOGFONT *pLogFont );
  100.     char *CNetscapeFontModule::converGenericFont(char *pExtracted);
  101.  
  102. public :
  103.     struct cfb *m_pGlobalFontBrokerObject; /* The global FontBroker Object */
  104.  
  105.     struct nffbp *m_pFontBrokerDisplayerInterface; /* The FontBroker Displayer interface */
  106.     struct nffbc *m_FontBrokerConsumerInterface; /* The FontBroker Consumer interface */
  107.     struct nffbu *m_pFontBrokerUtilityInterface; /* The FontBroker Utility interface */
  108.  
  109.     //struct cfp *m_pDisplayerObj;                 /* The global FontDisplayer Object */
  110.     struct nffp  *m_pFontDisplayerInterface;      /* The FontDisplayer interface */
  111.  
  112. private :
  113.     struct nfrc  *m_workingRC;            // avoid creating rc every time
  114.  
  115. };    // class CNetscapeFontModule
  116.  
  117.  
  118. ///////////////////////////////////////////////////////////////////////////////////
  119. // class Cyafont : yet another font class
  120. class CyaFont : public CObject
  121. {
  122. public :
  123.     // the standard stuff
  124.     CyaFont::CyaFont();
  125.     CyaFont::~CyaFont();
  126.     BOOL    CyaFont::IsEmptyFont() { return( m_pRenderableFont==NULL?TRUE:FALSE );     }
  127.  
  128.     // initializer
  129.     int    CyaFont::CreateNetscapeFontWithFMI(
  130.             MWContext *pContext,
  131.             HDC hDC, struct nffmi *pWantedFmi, double fontHeight );    
  132.     int    CyaFont::CreateNetscapeFont(
  133.         MWContext *pContext,
  134.         HDC        hDC, 
  135.         const char    *FmiName,
  136.         const char    *FmiCharset,
  137.         const char    *FmiEncoding,
  138.         int     FmiWeight,
  139.         int     FmiPitch,
  140.         int     FmiStyle,
  141.         int        FmiUnderline,
  142.         int     FmiOverstrike,
  143.         int     FmiPixelPerPointX,
  144.         int     FmiPixelPerPointY,
  145.         double    fontHeight                // not fmi field
  146.         );
  147.  
  148.     // the following 2 interfaces are for a quick integration with Navigator
  149.     // new code should use lower level interface.
  150.     int    CyaFont::CreateNetscapeFontWithLOGFONT( 
  151.         MWContext *pContext,
  152.         HDC hDC, LOGFONT *pLogFont, int extraAttributes = 0 );
  153.  
  154.     // service 
  155.     int        CyaFont::PrepareDrawText( HDC hDC );
  156.     int        CyaFont::EndDrawText( HDC hDC );
  157.     int        drawText( HDC hDC,int xx, int yy, char *str, int strLen);
  158.  
  159.     // attributes
  160.     int CyaFont::IsFixedFont() { return( m_pitch == nfSpacingProportional )? 0 : 1; }  // return 1 for nfSpacingDontCare
  161.     int CyaFont::GetAscent();
  162.     int CyaFont::GetDescent();
  163.     int CyaFont::GetMeanWidth();
  164.     int CyaFont::GetMaxWidth();
  165.     int CyaFont::GetHeight();
  166.     jint CyaFont::MeasureTextWidth( HDC hDC, jbyte *str, jsize strLen, jint *charLocs, jsize charLoc_len );
  167.     BOOL MeasureTextSize( HDC hDC, jbyte *str, jsize strLen, jint *charLocs, jsize charLoc_len, LPSIZE lpSize);
  168.     int CyaFont::CalculateMeanWidth(  HDC hDC, BOOL bFixed );
  169.  
  170.  
  171. private :
  172.     // helper functions
  173.     int    CyaFont::UpdateDisplayRC( HDC hDC );
  174.  
  175.  
  176. private :
  177.     struct nfrf        *m_pRenderableFont;
  178.     struct nfrc        *m_displayRC;            // avoid creating rc every time.
  179. #ifndef NO_PERFORMANCE_HACK
  180.     struct rc_data  *m_displayRCData;        // For performance of measure and draw
  181. #endif /* NO_PERFORMANCE_HACK */
  182.     int                m_iMeanWidth;
  183.     int                m_pitch;
  184.  
  185. #ifdef DEBUG_aliu
  186.     int                selectFlag;
  187. #endif
  188.  
  189. };    // class CyaFont
  190.  
  191. #endif
  192.