home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / gui / CFontReference.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.9 KB  |  118 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. #pragma once
  20. /*
  21.     Font References
  22.     Classes for holding a native Macintosh font id or a Web Font handle.
  23. */
  24. #include "uprefd.h"
  25. #include "xp_hash.h"
  26. #include "lo_ele.h"
  27.  
  28. #include "FontTypes.h"
  29.  
  30. #include "UPropFontSwitcher.h"
  31. #include "UFixedFontSwitcher.h"
  32. #include "UUTF8TextHandler.h"
  33.  
  34. typedef struct LO_TextAttr_struct LO_TextAttr;
  35.  
  36. class CFontReference
  37. {
  38. public:
  39.     CFontReference(const CCharSet *charSet, const LO_TextAttr *attr);
  40.     virtual ~CFontReference();
  41.     virtual void DrawText(int x, int y, char *text, int start, int end) = 0;
  42.     virtual short TextWidth(char *text, int firstByte, int byteCount) = 0;
  43.     virtual void GetFontInfo(FontInfo *fontInfo) = 0;
  44.     virtual void Apply() = 0;
  45.     
  46.     short GetMode() {return fMode;}
  47.     void SetMode(short mode) {fMode = mode;}
  48.     
  49.     static CFontReference *GetFontReference(const CCharSet *charSet, LO_TextAttr *attr, MWContext *context, Boolean underlineLinks);
  50.     
  51. protected:
  52.  
  53.     short fSize;
  54.     short fMode;
  55.     Boolean fIsGetFontInfoDirty;
  56.     FontInfo fCachedFontInfoValues;
  57.     
  58. private:
  59.     virtual void SynchToPort(GrafPtr port) = 0;
  60.     static short GetScaledTextSize(short size, short attrSize);
  61. };
  62.  
  63. class CNativeFontReference : public CFontReference
  64. {
  65. public:
  66.     CNativeFontReference(short font, const CCharSet *charSet, const LO_TextAttr *attr, Boolean underlineLinks);
  67.     virtual ~CNativeFontReference();
  68.     void DrawText(int x, int y, char *text, int start, int end);
  69.     short TextWidth(char *text, int firstByte, int byteCount);
  70.     short MeasureText(char *text, int firstByte, int byteCount, short* charLocs);
  71.     void GetFontInfo(FontInfo *fontInfo);
  72.     void Apply();
  73.     
  74.     static CFontReference *LookupNativeFont(char *fontName, const CCharSet *charSet, const LO_TextAttr *attr, Boolean underlineLinks);
  75.     static CFontReference *LookupGenericFont(char *fontName, const CCharSet *charSet, const LO_TextAttr *attr, Boolean underlineLinks);
  76.  
  77. private:
  78.     short fFont;
  79.     Style fStyle;
  80.     UFontSwitcher *fFontSwitcher;
  81.     UMultiFontTextHandler *fTextHandler;
  82.  
  83.     void SynchToPort(GrafPtr /*port*/) {};
  84. };
  85.  
  86. class CWebFontReference : public CFontReference
  87. {
  88. public:
  89.     CWebFontReference(WebFontHandle webFont, const CCharSet *charSet, const LO_TextAttr *attr);
  90.     virtual ~CWebFontReference();
  91.     void DrawText(int x, int y, char *text, int start, int end);
  92.     short TextWidth(char *text, int firstByte, int byteCount);
  93.      void GetFontInfo(FontInfo *fontInfo);
  94.     void Apply();
  95.  
  96.     static CFontReference *LookupWebFont(char *fontName, const CCharSet *charSet, const LO_TextAttr *attr, MWContext *context, Boolean underlineLinks);
  97.     static void Init();
  98.     static void Finish();
  99.     static Boolean NeedToReload(MWContext *context) { return nffbu_WebfontsNeedReload(sUtility, context, NULL); };
  100.  
  101. private:
  102.     RenderingContextHandle fRenderingContext;
  103.     RenderableFontHandle fRenderableFont;
  104.  
  105.     static FontBrokerHandle sBroker;
  106.     static FontBrokerUtilityHandle sUtility;
  107.     
  108.     static char *sCatalogPath;
  109.     
  110.     static XP_HashTable sPortHash;
  111.     
  112.     void SynchToPort(GrafPtr port);
  113.     static uint32 PortHash(const void *port);
  114.     static int PortCompFunction(const void *port1, const void *port2);
  115.     static RenderingContextHandle GetCachedRenderingContext(GrafPtr port);
  116. };
  117.  
  118.