home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / modules / libfont / src / wffpPeer.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.6 KB  |  200 lines

  1. /* -*- Mode: C++; tab-width: 8; 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.  * wffppeer.h (FontDisplayerPeerObject.h)
  20.  *
  21.  * This object is local to the FontDisplayer. One of these objects
  22.  * exist for every FontDisplayer that exists. All calls to the FontDisplayer
  23.  * are routed through this peer object. This takes care of loading and
  24.  * unloading the FontDisplayers as neccessary.
  25.  *
  26.  * dp Suresh <dp@netscape.com>
  27.  */
  28.  
  29.  
  30. #ifndef _wffpPeer_H_
  31. #define _wffpPeer_H_
  32.  
  33. #include "libfont.h"
  34. #include "nf.h"
  35.  
  36. #include "Mnfrf.h"
  37. #include "Mnffmi.h"
  38. #include "Mnfrc.h"
  39. #include "Mnffp.h"
  40. #include "Mnfstrm.h"
  41.  
  42. #include "wfList.h"
  43. #include "wfMime.h"
  44. #include "wfDlm.h"
  45. #include "wffpCat.h"
  46.  
  47. extern "C" void wf_unloadTimer(void *closure);
  48.  
  49. class FontDisplayerPeerObject {
  50. public:
  51.   typedef enum {
  52.     WF_FP_STATIC = 0,
  53.     WF_FP_DYNAMIC
  54. #if defined(XP_OS2)
  55.     /* insure that we know the size of this enum (4 bytes!) */
  56.     , WF_FP_TYPE_MAX=70000 
  57. #endif
  58.   } WF_FP_TYPE;
  59.  
  60. protected:
  61.  
  62.   // Whether this Displayer was loaded dynamically or not
  63.   WF_FP_TYPE fpType;
  64.   
  65.   // These are valid only if the fpType is 'WF_FP_DYNAMIC'
  66.   wfDlm dlm;
  67.  
  68.   // Name and description of the Displayer
  69.   char *displayerName;
  70.   char *displayerDescription;
  71.  
  72.   // Mimetypes that this displayer can support
  73.   wfMimeList mimeList;
  74.  
  75.   // Access Contol
  76.   // deleted : means this fp will no longer be used for this session and
  77.   //            is a candidate for garbage collection.
  78.   char deleted;
  79.   // disabled : means this fp will not be used unless enabled across session.
  80.   char disabled;
  81.  
  82.   // The actual displayer object that implements the nffp interface
  83.   struct nffp *fontDisplayer;
  84.  
  85.   int native;
  86.  
  87.   // Catalog
  88.   FontDisplayerCatalogObject catalog;
  89.  
  90.   // We need to refcount fh and stream opened by this displayer
  91.   // to decide when to unload the displayer
  92.   int streamCount;
  93.   wfList fhList;
  94.   void *unloadTimerId;
  95.  
  96. protected:
  97.   int load(void);
  98.   int unload(void);
  99.   int finalize(void);
  100.   int finalizeExceptDlmAndDisabled(void);
  101.  
  102. public:
  103.   //
  104.   // Constructor and Destructor
  105.   //
  106.  
  107.   FontDisplayerPeerObject(struct nffp *fp);
  108.   FontDisplayerPeerObject(const char *dlmName);
  109.   FontDisplayerPeerObject(FontCatalogFile &fc);
  110.   ~FontDisplayerPeerObject();
  111.  
  112.   //
  113.   // Fontdisplayer routines
  114.   //
  115.  
  116.   jdouble *EnumerateSizes(struct nfrc *rc, void *fh);
  117.   struct nfrf * CreateRenderableFont(struct nfrc *rc, void *fh, jdouble pointsize);
  118.   void * LookupFont(struct nfrc *rc, struct nffmi *fmi, const char *accessor);
  119.   void * CreateFontFromFile(struct nfrc *rc, const char *mimetype,
  120.       const char *fontFilename, const char *urlOfPage);
  121.   struct nfstrm * CreateFontStreamHandler(struct nfrc *rc, const char *urlOfPage);
  122.   struct nffmi *GetMatchInfo(void *fh);
  123.   private:
  124.   jint ReleaseFontHandle(void *fh);
  125.  
  126.   //
  127.   // Catalogue routines
  128.   //
  129.   public:
  130.   struct nffmi ** ListFonts(struct nfrc *rc, struct nffmi *fmi);
  131.   jdouble * ListSizes(struct nfrc *rc, struct nffmi *fmi);
  132.  
  133.   //
  134.   // mime handling routines
  135.   //
  136.   const char * getMimetypeFromExtension(const char *ext);
  137.   
  138.   int countMimetypes();
  139.  
  140.   int isMimetypeEnabled(const char *mimetype);
  141.   int disableMimetype(const char *mimetype);
  142.  
  143.   // If this wffpPeer matches the dlm_name and
  144.   //    if the dlm has changed, returns 1.
  145.   //    else returns 0
  146.   // If dlm_name doesn't match the dlm this wffpPeer is associated with, returns -1.
  147.   int dlmChanged(const char *dlm_name);
  148.  
  149.   // resync:
  150.   // If the dlm changed, then this will reload the dlm and reinitialize
  151.   //
  152.   // WARNING: before calling this, the CALLER needs to ensure that all references
  153.   // to this wffpPeer is removed as after resync(), the kind of fonts this displayer
  154.   // could serve could change and worse, this displayer may get deleted too.
  155.   //
  156.   void resync(void);
  157.   int enableMimetype(const char *mimetype);
  158.  
  159.   //
  160.   // Catalog routines
  161.   //
  162.   jint describe(FontCatalogFile &fc);
  163.   jint reconstruct(FontCatalogFile &fc);
  164.   int queryCatalog(struct nfrc *rc, struct nffmi *fmi);
  165.  
  166.   //
  167.   // Additional routines
  168.   //
  169.  
  170.   const char *name(void);
  171.   int isNative(void);
  172.   int isDeleted(void);
  173.   int isLoaded(void);
  174.  
  175.   // For refcounting and deciding when to unload displayers
  176.   void StreamCreated(struct nfstrm *strm);
  177.   void StreamDone(struct nfstrm *strm);
  178.   void FontHandleCreated(void *fh);
  179.   void FontHandleDone(void *fh);
  180.   void decideToUnload(void);
  181.  
  182.   //
  183.   // For display in the about:fonts information, this will generate html
  184.   //
  185.   char *aboutData(void);
  186.  
  187.   // These return -1 if error; 0 if success
  188.   int disableDisplayer(void);
  189.   int enableDisplayer(void);
  190.   int isDisplayerEnabled(void);
  191.  
  192.   // Register a converter to libnet/ so that the association between mimetype
  193.   // and extensions that are supported is recognized.
  194.   int registerConverters(void);
  195.  
  196.   friend void wf_unloadTimer(void *closure);
  197. };
  198.  
  199. #endif /* _wffpPeer_H_ */
  200.