📄 psapi.c
字号:
{
g_pdElement[lelement] = BADHANDLE;
g_pdELen[lelement] = 0;
}
else
{
g_pdElement[lelement] = val.ev_handle;
g_pdELen[lelement] = val.ev_length;
}
}
}
return (-errcode);
}
/*----------------------------------------------------------------------+
| This routine is called on loading of the api printer driver. It |
| checks to see if _PDPARMS has been created and if so, it then loads |
| in certain elements of the array into an internal copy. |
| This is done once, so any changes made to the xBase version of |
| _PDPARMS after this, will not take any effect on our copy. This is |
| done so we don't continually have to call back to FoxPro to obtain |
| the value of a certain element in _PDPARMS array. |
+----------------------------------------------------------------------*/
FAR pdonload()
{
Locator loc; // Locator for _PDPARMS
int errcode; // internal error code
NTI nti; // Name Table Index for _PDPARMS
Value val;
int element;
TEXT varflag = FALSE,
create = FALSE;
FPFI load_func;
TEXT load_elem[20];
int load_len=0;
long chksum;
if ((nti = _NameTableIndex("_PDPARMS")) >= 0)
{
if (_FindVar(nti, -1, &loc)) // Is _PDPARMS around?
{
if (loc.l_subs == 0)
varflag = TRUE;
else
{
g_pdparms = loc; // Save the Locator to it.
varflag = loadPDParms(0, loc.l_sub1);
g_lmargin = pdNval(11); // Get the Left Margin
g_length = 0;
/*----------------------------------------------------------------------+
| The following line tells us how many times this api routine has been|
| loaded. This is needed in case a user loads a printer drivers and |
| thus the api, and then loads the api routine via the SET LIBRARY TO |
| command. Without this, we would release the local copy of _PDPARMS |
| (which rely heavily upon.) |
+----------------------------------------------------------------------*/
pdStoreNVal(39, pdNval(39) + 1);
/*----------------------------------------------------------------------+
| The following code was added as and enhancement request. It stores |
| the address of the procedure loadPDParms and a four byte checksum |
| of this address into the last element of _PDPARMS. If the user |
| wants to update the api's internal copy of _PDPARMS, it can now |
| be done by loading the library PDUDATE.PLB. |
| |
| Note: The address of loadPDParms() function must be placed in the |
| last element in the _PDPARMS array in order for PDUPDATE to work. |
+----------------------------------------------------------------------*/
load_func = loadPDParms;
_MemMove(load_elem, &load_func, 4);
load_len = 4;
chksum = ~(long) load_func;
_MemMove(load_elem + load_len, &chksum, 4);
load_len +=4;
val.ev_type = 'C';
val.ev_handle = _AllocHand(load_len);
if (val.ev_handle != BADHANDLE)
{
val.ev_length = load_len;
_MemMove(_HandToPtr(val.ev_handle), load_elem, load_len);
}
else
val.ev_length = 0;
if ((loc.l_sub1 = _ALen(nti, AL_ELEMENTS)) >= 0)
_Store(&loc, &val);
}
}
else
create = TRUE;
}
else
create = TRUE;
if (create) // Create _PDPARMS
{
loc.l_subs = 0;
if (errcode = _NewVar("_PDPARMS", &loc, NV_PUBLIC) < 0)
_Error(errcode);
else
varflag = TRUE;
}
if (varflag) // Setup the Value Structure to return the -1
{ // signifying an error occured.
val.ev_type = 'I';
val.ev_width = 10;
val.ev_long = -1;
_Store(&loc, &val);
}
}
/*----------------------------------------------------------------------+
| Release the array of handles which we have accumulated for our copy |
| of _PDPARMS. This only done if the value in _PDPARMS(39) is 1. |
+----------------------------------------------------------------------*/
FAR pdonunload()
{
int lelement;
MHANDLE hand;
if (pdNval(39) == 1)
_Release(g_pdparms.l_NTI);
else
pdStoreNVal(39, pdNval(39) - 1);
for (lelement=0; lelement < PDLOCALELES; lelement++)
{
if (hand = g_pdElement[lelement])
_FreeHand(hand);
}
}
/*----------------------------------------------------------------------+
| Put together the strings which we have built separately. This |
| in three strings (Beginning, Middle, and End) and put's them in |
| the correct order. |
+----------------------------------------------------------------------*/
static void BldStMidEnd(int element,
TEXT FAR *startchars, USHORT FAR *stlen,
TEXT FAR *midchars, USHORT FAR *midlen,
TEXT FAR *endchars, USHORT FAR *endlen,
int flag)
{
TEXT buff[512];
USHORT bufflen;
if (flag)
{
_MemMove(buff, startchars, *stlen);
bufflen = *stlen;
}
/* Build startchars */
*stlen = *midlen = *endlen = 0;
LocalpdCval(19, startchars, stlen);
PDAdd1Char(startchars, ' ', stlen);
if (flag)
{
_MemMove(startchars + *stlen, buff, bufflen);
*stlen += bufflen;
}
else
{
PDAdd1Char(startchars, ' ', stlen);
LocalpdCval(18, startchars, stlen);
}
PDAddChars(startchars, " font ", stlen);
/* Build middle chars */
LocalpdCval(element, midchars, midlen);
PDAddChars(midchars, (element == 19) ? " up " : " dn ", midlen);
/* Build endchars */
PDAdd1Char(endchars, ' ', endlen);
PDAddChars(endchars, "norm ", endlen);
LocalpdCval(element, endchars, endlen);
PDAddChars(endchars, (element == 19) ? " dn " : " up ", endlen);
}
/*----------------------------------------------------------------------+
| PDObject is the procedure which gets called everytime FoxPro is |
| about to print any kind of object. This includes fields, text, |
| boxes, numbers, etc. Each object can have an attribute associated |
| with it. This printer driver does not take into account if a user |
| has enclosed his own attribute characters in the style code box. |
| Thus, if it encounters any that are meaningful to himself, he will |
| use them. |
| |
| This routine also builds the starting and ending codes that would |
| normally be sent on object start and object end. This is done for |
| efficiency reasons. |
+----------------------------------------------------------------------*/
FAR pdobject(ParamBlk FAR *pblk)
{
TEXT startchars[512], buff[512], endchars[512];
USHORT stlen=0, bufflen=0, endlen=0, reslen;
MHANDLE srchand, mhand, reshand=BADHANDLE;
int srclen, attrlen=0;
TEXT FAR *attribs;
TEXT FAR *srctext;
TEXT FAR *restext;
unsigned styles=0;
Value retval;
srchand = pblk->p[0].val.ev_handle; // The object
srclen = pblk->p[0].val.ev_length;
if ((srchand != BADHANDLE) && (srclen > 0))
{
mhand = pblk->p[1].val.ev_handle; // The attributes
attrlen = pblk->p[1].val.ev_length;
if ((mhand != BADHANDLE) && (attrlen > 0))
{
_HLock(mhand);
attribs = ((TEXT FAR *)_HandToPtr(mhand));
if (mystrchr('B', attribs, attrlen))
{
/* The object is BOLD */
LocalpdCval(13, buff, &bufflen);
if (bufflen)
{
LocalpdCval(12, startchars, &stlen);
LocalpdCval(15, startchars, &stlen);
LocalpdCval(13, startchars, &stlen);
bufflen=0;
}
else
LocalpdCval(18,startchars, &stlen);
styles |= P_BOLD;
}
if (mystrchr('I', attribs, attrlen))
{
/* The object is ITALIC */
if (styles)
LocalpdCval(14, startchars, &stlen);
else
{
LocalpdCval(14, buff, &bufflen);
if (bufflen)
{
LocalpdCval(12, startchars, &stlen);
LocalpdCval(15, startchars, &stlen);
if (pdLVal(38))
LocalpdCval(16, startchars, &stlen);
LocalpdCval(14, startchars, &stlen);
bufflen=0;
}
else
LocalpdCval(18, startchars, &stlen);
}
styles |= P_ITALIC;
}
if (mystrchr('U', attribs, attrlen)) /* The object is UNDERLINED */
styles |= P_UNDERLINE;
if (mystrchr('R', attribs, attrlen))
{
/* SUPERSCRIPT the object */
BldStMidEnd(19, startchars, &stlen, buff, &bufflen,
endchars, &endlen, styles & (P_BOLD|P_ITALIC));
styles |= P_RAISED;
}
else if (mystrchr('L', attribs, attrlen))
{
/* SUBSCRIPT the object */
BldStMidEnd(20, startchars, &stlen, buff, &bufflen,
endchars, &endlen, styles & (P_BOLD|P_ITALIC));
styles |= P_LOWERED;
}
else if (styles & (P_BOLD | P_ITALIC))
{
/* Build startchars (in buff) */
LocalpdCval(3, buff, &bufflen);
PDAdd1Char(buff, ' ', &bufflen);
_MemMove(buff + bufflen, startchars, stlen);
bufflen += stlen;
PDAddChars(buff, " font ", &bufflen);
stlen = startchars[0] = 0;
/* Build endchars */
PDAddChars(endchars, " norm ", &endlen);
}
_HUnLock(mhand); // Since we're done with the handle, UnLock it
}
if (mystrchr('J', attribs, attrlen))
styles |= P_RIGHT; /* Check for right justification. */
else if (mystrchr('C', attribs, attrlen))
styles |= P_CENTER; /* Check for centering. */
// Check for the special characters
mhand = chk_special(srchand, &srclen,
(styles & (P_UNDERLINE|P_CENTER|P_RIGHT)));
_HLock(mhand);
srctext = _HandToPtr(mhand);
if ((reshand = _AllocHand(PDALLOCSIZE)) == BADHANDLE)
{
_HUnLock(mhand);
_FreeHand(mhand);
_Error(182); // Insufficient memory
}
_HLock(reshand);
restext = _HandToPtr(reshand);
reslen = 0;
if (styles && !(styles == P_UNDERLINE))
attrlen = (bufflen + stlen + endlen);
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -