home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / modules / libfont / src / cfmi.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.0 KB  |  163 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 (cfmi) CFontMatchInfo Interface
  21.  * implementation and its C++ implementation viz (fmi) FontMatchInfoObject.
  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 "Pcfmi.h"
  32.  
  33. // The actual C++ object
  34. #include "fmi.h"
  35.  
  36. // Uses: The nffmi interface
  37. #include "Mnffmi.h"
  38.  
  39. /****************************************************************************
  40.  *                 Implementation of common interface methods                    *
  41.  ****************************************************************************/
  42.  
  43. #ifdef OVERRIDE_cfmi_getInterface
  44. extern "C" JMC_PUBLIC_API(void*)
  45. /*ARGSUSED*/
  46. _cfmi_getInterface(struct cfmi* self, jint op, const JMCInterfaceID* iid, JMCException* *exc)
  47. {
  48.     if (memcmp(iid, &nffmi_ID, sizeof(JMCInterfaceID)) == 0)
  49.         return cfmiImpl2cfmi(cfmi2cfmiImpl(self));
  50.     return _cfmi_getBackwardCompatibleInterface(self, iid, exc);
  51. }
  52. #endif /* OVERRIDE_cfmi_getInterface */
  53.  
  54. extern "C" JMC_PUBLIC_API(void*)
  55. /*ARGSUSED*/
  56. _cfmi_getBackwardCompatibleInterface(struct cfmi* self,
  57.                                      const JMCInterfaceID* iid,
  58.                                      struct JMCException* *exceptionThrown)
  59. {
  60.     return(NULL);
  61. }
  62.  
  63. extern "C" JMC_PUBLIC_API(void)
  64. /*ARGSUSED*/
  65. _cfmi_init(struct cfmi* self, struct JMCException* *exceptionThrown,
  66.            const char* name, const char* charset, const char* encoding,
  67.            jint weight, jint pitch, jint style, jint underline, jint strikeOut,
  68.            jint resolutionX, jint resolutionY)
  69. {
  70.     cfmiImpl *oimpl = cfmi2cfmiImpl(self);
  71.     FontMatchInfoObject *fmiob = (FontMatchInfoObject *)oimpl->object;
  72.     fmiob = new FontMatchInfoObject(name, charset, encoding, weight,
  73.                                     pitch, style, underline, strikeOut,
  74.                                     resolutionX, resolutionY);
  75.     if (fmiob == NULL)
  76.       {
  77.         JMC_EXCEPTION(exceptionThrown, JMCEXCEPTION_OUT_OF_MEMORY);
  78.       }
  79.     else
  80.       {
  81.         oimpl->object = fmiob;
  82.       }
  83. }
  84.  
  85.  
  86. #ifdef OVERRIDE_cfmi_finalize
  87. extern "C" JMC_PUBLIC_API(void)
  88. /*ARGSUSED*/
  89. _cfmi_finalize(struct cfmi* self, jint op, JMCException* *exception)
  90. {
  91.     struct cfmiImpl *oimpl = cfmi2cfmiImpl(self);
  92.     FontMatchInfoObject *fmiob = (FontMatchInfoObject *)oimpl->object;
  93.     delete fmiob;
  94.     
  95.     /* Finally, free the memory for the object containter. */
  96.     XP_FREEIF(self);
  97. }
  98. #endif /* OVERRIDE_cfmi_finalize */
  99.  
  100. #ifdef OVERRIDE_cfmi_toString
  101. JMC_PUBLIC_API(const char*)
  102. /*ARGSUSED*/
  103. _cfmi_toString(struct cfmi* self, jint op, JMCException* *exc)
  104. {
  105.     cfmiImpl *oimpl = cfmi2cfmiImpl(self);
  106.     XP_ASSERT(oimpl->header.refcount);
  107.     FontMatchInfoObject *fmiob = (FontMatchInfoObject *)oimpl->object;
  108.     return(fmiob->describe());
  109. }
  110. #endif
  111.  
  112. #ifdef OVERRIDE_cfmi_equals
  113. JMC_PUBLIC_API(jbool)
  114. /*ARGSUSED*/
  115. _cfmi_equals(struct cfmi* self, jint op, void* obj, JMCException* *exc)
  116. {
  117.     cfmiImpl *oimpl = cfmi2cfmiImpl(self);
  118.     XP_ASSERT(oimpl->header.refcount);
  119.     FontMatchInfoObject *fmiob = (FontMatchInfoObject *)oimpl->object;
  120.     return(fmiob->IsEquivalent((struct nffmi *)obj) > 0);
  121. }
  122. #endif
  123.  
  124.  
  125. /****************************************************************************
  126.  *                 Implementation of Object specific methods                    *
  127.  ****************************************************************************/
  128.  
  129. extern "C" JMC_PUBLIC_API(void *)
  130. /*ARGSUSED*/
  131. _cfmi_GetValue(struct cfmi* self, jint op, const char *attribute,
  132.                struct JMCException* *exceptionThrown)
  133. {
  134.     cfmiImpl *oimpl = cfmi2cfmiImpl(self);
  135.     XP_ASSERT(oimpl->header.refcount);
  136.     FontMatchInfoObject *fmiob = (FontMatchInfoObject *)oimpl->object;
  137.     return(fmiob->GetValue(attribute));
  138. }
  139.  
  140.  
  141. extern "C" JMC_PUBLIC_API(void *)
  142. /*ARGSUSED*/
  143. _cfmi_ListAttributes(struct cfmi* self, jint op,
  144.                      struct JMCException* *exceptionThrown)
  145. {
  146.     cfmiImpl *oimpl = cfmi2cfmiImpl(self);
  147.     XP_ASSERT(oimpl->header.refcount);
  148.     FontMatchInfoObject *fmiob = (FontMatchInfoObject *)oimpl->object;
  149.     return((void *)fmiob->ListAttributes());
  150. }
  151.  
  152.  
  153. extern "C" JMC_PUBLIC_API(jint)
  154. /*ARGSUSED*/
  155. _cfmi_IsEquivalent(struct cfmi* self, jint op, struct nffmi *fmi,
  156.                    struct JMCException* *exceptionThrown)
  157. {
  158.     cfmiImpl *oimpl = cfmi2cfmiImpl(self);
  159.     XP_ASSERT(oimpl->header.refcount);
  160.     FontMatchInfoObject *fmiob = (FontMatchInfoObject *)oimpl->object;
  161.     return(fmiob->IsEquivalent(fmi));
  162. }
  163.