~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/gfx/src/os2/nsGfxDefs.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * The contents of this file are subject to the Mozilla Public License
 
3
 * Version 1.1 (the "License"); you may not use this file except in
 
4
 * compliance with the License. You may obtain a copy of the License at
 
5
 * http://www.mozilla.org/MPL/
 
6
 *
 
7
 * Software distributed under the License is distributed on an "AS IS"
 
8
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 
9
 * License for the specific language governing rights and limitations
 
10
 * under the License.
 
11
 *
 
12
 * The Original Code is the Mozilla OS/2 libraries.
 
13
 *
 
14
 * The Initial Developer of the Original Code is John Fairhurst,
 
15
 * <john_fairhurst@iname.com>.  Portions created by John Fairhurst are
 
16
 * Copyright (C) 1999 John Fairhurst. All Rights Reserved.
 
17
 *
 
18
 * Contributor(s): 
 
19
 *
 
20
 */
 
21
 
 
22
#include "nsGfxDefs.h"
 
23
 
 
24
#ifdef DEBUG
 
25
  #include <string.h>
 
26
  #include <ctype.h>
 
27
 
 
28
//DJ  #include "nsLog.h"
 
29
//DJ  NS_IMPL_LOG_ENABLED (GFXLog)
 
30
//DJ  #define DPRINTF NS_LOG_PRINTF(GFXLog)
 
31
  #include <stdio.h>
 
32
  #define DPRINTF printf
 
33
#else
 
34
  #include <stdio.h>
 
35
  #define DPRINTF printf
 
36
#endif
 
37
 
 
38
#include "nsDeviceContextSpecOS2.h"
 
39
 
 
40
#include <stdlib.h>
 
41
 
 
42
BOOL GetTextExtentPoint32(HPS aPS, const char* aString, int aLength, PSIZEL aSizeL)
 
43
{
 
44
  BOOL rc = TRUE;
 
45
  POINTL ptls[5];
 
46
 
 
47
  aSizeL->cx = 0;
 
48
 
 
49
  while(aLength > 0 && rc == TRUE) {
 
50
    ULONG thislen = min(aLength, 512);
 
51
    rc = GFX (::GpiQueryTextBox(aPS, thislen, (PCH)aString, 5, ptls), FALSE);
 
52
    aSizeL->cx += ptls[TXTBOX_CONCAT].x;
 
53
    aLength -= thislen;
 
54
    aString += thislen;
 
55
  }
 
56
 
 
57
  aSizeL->cy = ptls[TXTBOX_TOPLEFT].y - ptls[TXTBOX_BOTTOMLEFT].y;
 
58
  return rc;
 
59
}
 
60
 
 
61
BOOL ExtTextOut(HPS aPS, int X, int Y, UINT fuOptions, const RECTL* lprc,
 
62
                const char* aString, unsigned int aLength, const int* pSpacing)
 
63
{
 
64
  long rc = GPI_OK;
 
65
  POINTL ptl = {X, Y};
 
66
 
 
67
  GFX (::GpiMove(aPS, &ptl), FALSE);
 
68
 
 
69
  // GpiCharString has a max length of 512 chars at a time...
 
70
  while (aLength > 0 && rc == GPI_OK) {
 
71
    ULONG ulChunkLen = min(aLength, 512);
 
72
    if (pSpacing) {
 
73
      rc = GFX (::GpiCharStringPos(aPS, nsnull, CHS_VECTOR, ulChunkLen,
 
74
                                   (PCH)aString, (PLONG)pSpacing), GPI_ERROR);
 
75
      pSpacing += ulChunkLen;
 
76
    } else {
 
77
      rc = GFX (::GpiCharString(aPS, ulChunkLen, (PCH)aString), GPI_ERROR);
 
78
    }
 
79
    aLength -= ulChunkLen;
 
80
    aString += ulChunkLen;
 
81
  }
 
82
 
 
83
  if (rc == GPI_OK)
 
84
    return TRUE;
 
85
  else
 
86
    return FALSE;
 
87
}
 
88
 
 
89
static BOOL bIsDBCS;
 
90
static BOOL bIsDBCSSet = FALSE;
 
91
 
 
92
BOOL IsDBCS()
 
93
{
 
94
  if (!bIsDBCSSet) {
 
95
    // the following lines of code determine whether the system is a DBCS country
 
96
    APIRET rc;
 
97
    COUNTRYCODE ctrycodeInfo = {0};
 
98
    CHAR        achDBCSInfo[12] = {0};                  // DBCS environmental vector
 
99
    ctrycodeInfo.country  = 0;                          // current country
 
100
    ctrycodeInfo.codepage = 0;                          // current codepage
 
101
 
 
102
    rc = DosQueryDBCSEnv(sizeof(achDBCSInfo), &ctrycodeInfo, achDBCSInfo);
 
103
    if (rc == NO_ERROR)
 
104
    {
 
105
        // NON-DBCS countries will have four bytes in the first four bytes of the
 
106
        // DBCS environmental vector
 
107
        if (achDBCSInfo[0] != 0 || achDBCSInfo[1] != 0 ||
 
108
            achDBCSInfo[2] != 0 || achDBCSInfo[3] != 0)
 
109
        {
 
110
           bIsDBCS = TRUE;
 
111
        }
 
112
        else
 
113
        {
 
114
           bIsDBCS = FALSE;
 
115
        }
 
116
    } else {
 
117
       bIsDBCS = FALSE;
 
118
    } /* endif */
 
119
    bIsDBCSSet = TRUE;
 
120
  } /* endif */
 
121
  return bIsDBCS;
 
122
}
 
123
 
 
124
 
 
125
 
 
126
 
 
127
// Module-level data ---------------------------------------------------------
 
128
#ifdef DEBUG
 
129
void DEBUG_LogErr(long ReturnCode, const char* ErrorExpression,
 
130
                  const char* FileName, const char* FunctionName, long LineNum)
 
131
{
 
132
   char TempBuf [300];
 
133
 
 
134
   strcpy (TempBuf, ErrorExpression);
 
135
   char* APIName = TempBuf;
 
136
 
 
137
   char* ch = strstr (APIName , "(");                 // Find start of function parameter list
 
138
   if (ch != NULL)                                    // Opening parenthesis found - it is a function
 
139
   {
 
140
      while (isspace (*--ch)) {}                      // Remove whitespaces before opening parenthesis
 
141
      *++ch = '\0';
 
142
 
 
143
      if (APIName [0] == ':' && APIName [1] == ':')   // Remove global scope operator
 
144
         APIName += 2;
 
145
 
 
146
      while (isspace (*APIName))                      // Remove spaces before function name
 
147
         APIName++;
 
148
   }
 
149
 
 
150
 
 
151
   USHORT ErrorCode = ERRORIDERROR (::WinGetLastError(0));
 
152
 
 
153
   printf("GFX_Err: %s = 0x%X, 0x%X (%s - %s,  line %ld)\n", APIName, ReturnCode,
 
154
          ErrorCode, FileName, FunctionName, LineNum);
 
155
}
 
156
#endif
 
157
 
 
158
void PMERROR( const char *api)
 
159
{
 
160
   ERRORID eid = ::WinGetLastError(0);
 
161
   USHORT usError = ERRORIDERROR(eid);
 
162
   DPRINTF ( "%s failed, error = 0x%X\n", api, usError);
 
163
}
 
164