home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / modules / libfont / src / cf.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.7 KB  |  202 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.  *
  20.  * Implements a link between the (cf) CFont Interface
  21.  * implementation and its C++ implementation viz (f) FontObject.
  22.  *
  23.  * dp Suresh <dp@netscape.com>
  24.  */
  25.  
  26.  
  27. #include "libfont.h"
  28.  
  29. // The C implementation definition of the interface.
  30. // This links it to the C++ implementation
  31. #include "Pcf.h"
  32.  
  33. // The actual C++ object
  34. #include "f.h"
  35.  
  36. // Uses:    The nff interface
  37. #include "Mnff.h"
  38.  
  39. // The finalize methods removes the font from the fontbrokers
  40. // font object cache. Hence it needs to access the fontbroker.
  41. #include "Pcfb.h"
  42. #include "fb.h"
  43.  
  44. /****************************************************************************
  45.  *                 Implementation of common interface methods                    *
  46.  ****************************************************************************/
  47. #ifdef OVERRIDE_cf_getInterface
  48. extern "C" JMC_PUBLIC_API(void*)
  49. /*ARGSUSED*/
  50. _cf_getInterface(struct cf* self, jint op, const JMCInterfaceID* iid, JMCException* *exc)
  51. {
  52.     if (memcmp(iid, &nff_ID, sizeof(JMCInterfaceID)) == 0)
  53.         return cfImpl2cf(cf2cfImpl(self));
  54.     return _cf_getBackwardCompatibleInterface(self, iid, exc);
  55. }
  56. #endif /* OVERRIDE_cf_getInterface */
  57.  
  58. extern "C" JMC_PUBLIC_API(void*)
  59. /*ARGSUSED*/
  60. _cf_getBackwardCompatibleInterface(struct cf* self, const JMCInterfaceID* iid,
  61.                                    struct JMCException* *exceptionThrown)
  62. {
  63.     return(NULL);
  64. }
  65.  
  66. extern "C" JMC_PUBLIC_API(void)
  67. /*ARGSUSED*/
  68. _cf_init(struct cf* self, struct JMCException* *exceptionThrown,
  69.          struct nfrc *rc)
  70. {
  71.     cfImpl *oimpl = cf2cfImpl(self);
  72.     FontObject *fobj = new FontObject((struct nff *)self, rc);
  73.     if (fobj == NULL)
  74.       {
  75.         JMC_EXCEPTION(exceptionThrown, JMCEXCEPTION_OUT_OF_MEMORY);
  76.       }
  77.     else
  78.       {
  79.         oimpl->object = fobj;
  80.       }
  81.     return;
  82. }
  83.  
  84.  
  85. #ifdef OVERRIDE_cf_finalize
  86. extern "C" JMC_PUBLIC_API(void)
  87. /*ARGSUSED*/
  88. _cf_finalize(struct cf* self, jint op, JMCException* *exception)
  89. {
  90.     /* Release this font object from the fontObjectCache in the Broker */
  91.     cfbImpl *fbimpl = cfb2cfbImpl(WF_fbc);
  92.     FontBrokerObject *fbobj = (FontBrokerObject *)fbimpl->object;
  93.  
  94.     WF_TRACEMSG( ("NF: Deleting font object [0x%x].", fbobj) );
  95.     fbobj->fontObjectCache.releaseFont((struct nff *)self);
  96.     
  97.     /* Delete the font object */
  98.     struct cfImpl *oimpl = cf2cfImpl(self);
  99.     FontObject *fob = (FontObject *)oimpl->object;
  100.     delete fob;
  101.     
  102.     /* Finally, free the memory for the object containter. */
  103.     XP_FREEIF(self);
  104. }
  105. #endif /* OVERRIDE_cf_finalize */
  106.  
  107.  
  108. #ifdef OVERRIDE_cf_release
  109. JMC_PUBLIC_API(void)
  110. /*ARGSUSED*/
  111. _cf_release(struct cf* self, jint op, JMCException* *exc)
  112. {
  113.     cfImplHeader* impl = (cfImplHeader*)cf2cfImpl(self);
  114.     --impl->refcount;
  115.  
  116.     // Run the GC
  117.     cfImpl *oimpl = cf2cfImpl(self);
  118.     FontObject *fob = (FontObject *)oimpl->object;
  119.     int ret = fob->GC();
  120.     
  121.     if (impl->refcount == 0)
  122.     {
  123.         cf_finalize(self, exc);
  124.     }
  125. }
  126. #endif
  127.  
  128.  
  129. /****************************************************************************
  130.  *                 Implementation of Object specific methods                    *
  131.  ****************************************************************************/
  132.  
  133. extern "C" JMC_PUBLIC_API(jint)
  134. /*ARGSUSED*/
  135. _cf_GetState(struct cf* self, jint op, struct JMCException* *exceptionThrown)
  136. {
  137.     cfImpl *oimpl = cf2cfImpl(self);
  138.     XP_ASSERT(oimpl->header.refcount);
  139.     FontObject *fob = (FontObject *)oimpl->object;
  140.     return((jint)fob->GetState());
  141. }
  142.  
  143.  
  144. extern "C" JMC_PUBLIC_API(void*)
  145. /*ARGSUSED*/
  146. _cf_EnumerateSizes(struct cf* self, jint op, struct nfrc *rc,
  147.                    struct JMCException* *exceptionThrown)
  148. {
  149.     cfImpl *oimpl = cf2cfImpl(self);
  150.     XP_ASSERT(oimpl->header.refcount);
  151.     FontObject *fob = (FontObject *)oimpl->object;
  152.     return(fob->EnumerateSizes(rc));
  153. }
  154.  
  155.  
  156. extern "C" JMC_PUBLIC_API(struct nfrf*)
  157. /*ARGSUSED*/
  158. _cf_GetRenderableFont(struct cf* self, jint op, struct nfrc *rc,
  159.                       jdouble pointsize, struct JMCException* *exceptionThrown)
  160. {
  161.     cfImpl *oimpl = cf2cfImpl(self);
  162.     XP_ASSERT(oimpl->header.refcount);
  163.     FontObject *fob = (FontObject *)oimpl->object;
  164.     return(fob->GetRenderableFont(rc, pointsize));
  165. }
  166.  
  167.  
  168. extern "C" JMC_PUBLIC_API(struct nffmi*)
  169. /*ARGSUSED*/
  170. _cf_GetMatchInfo(struct cf* self, jint op, struct nfrc *rc,
  171.                  jint pointsize, struct JMCException* *exceptionThrown)
  172. {
  173.     cfImpl *oimpl = cf2cfImpl(self);
  174.     XP_ASSERT(oimpl->header.refcount);
  175.     FontObject *fob = (FontObject *)oimpl->object;
  176.     return(fob->GetMatchInfo(rc, pointsize));
  177. }
  178.  
  179.  
  180. extern "C" JMC_PUBLIC_API(jint)
  181. /*ARGSUSED*/
  182. _cf_GetRcMajorType(struct cf* self, jint op,
  183.                    struct JMCException* *exceptionThrown)
  184. {
  185.     cfImpl *oimpl = cf2cfImpl(self);
  186.     XP_ASSERT(oimpl->header.refcount);
  187.     FontObject *fob = (FontObject *)oimpl->object;
  188.     return(fob->GetRcMajorType());
  189. }
  190.  
  191.  
  192. extern "C" JMC_PUBLIC_API(jint)
  193. /*ARGSUSED*/
  194. _cf_GetRcMinorType(struct cf* self, jint op,
  195.                    struct JMCException* *exceptionThrown)
  196. {
  197.     cfImpl *oimpl = cf2cfImpl(self);
  198.     XP_ASSERT(oimpl->header.refcount);
  199.     FontObject *fob = (FontObject *)oimpl->object;
  200.     return(fob->GetRcMinorType());
  201. }
  202.