summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Walzer <kw@codebykevin.com>2021-05-06 15:51:40 (GMT)
committerKevin Walzer <kw@codebykevin.com>2021-05-06 15:51:40 (GMT)
commitd56d5577a75d2a367728e7f2fd9ff68ba98bed20 (patch)
treeed0c2bd2e5bb68f35e9e478e8f33d6c41660dfc3
parent43c2e0df3791777a06661fa4a852871ff0a7cabf (diff)
downloadtk-d56d5577a75d2a367728e7f2fd9ff68ba98bed20.zip
tk-d56d5577a75d2a367728e7f2fd9ff68ba98bed20.tar.gz
tk-d56d5577a75d2a367728e7f2fd9ff68ba98bed20.tar.bz2
Try to obtain printer HDC at script level for printing
-rw-r--r--library/print.tcl2
-rw-r--r--win/Makefile.in1
-rw-r--r--win/makefile.vc1
-rw-r--r--win/tkWinHDC.c295
-rw-r--r--win/tkWinHDC.h29
-rw-r--r--win/tkWinPrint.c54
6 files changed, 54 insertions, 328 deletions
diff --git a/library/print.tcl b/library/print.tcl
index 54d775d..c6fb1d8 100644
--- a/library/print.tcl
+++ b/library/print.tcl
@@ -46,7 +46,7 @@ namespace eval ::tk::print {
}
#Next, set values.
- set printargs(hDC) $::tk::print::printer_name
+ set printargs(hDC) ::tk::print::_gethdc
set printargs(pw) $::tk::print::paper_width
set printargs(pl) $::tk::print::paper_height
set printargs(lm) 100 ;#$::tk::print::margin_left
diff --git a/win/Makefile.in b/win/Makefile.in
index d46ce74..849e79c 100644
--- a/win/Makefile.in
+++ b/win/Makefile.in
@@ -309,7 +309,6 @@ TK_OBJS = \
tkWinEmbed.$(OBJEXT) \
tkWinFont.$(OBJEXT) \
tkWinGDI.$(OBJEXT) \
- tkWinHDC.$(OBJEXT) \
tkWinIco.$(OBJEXT) \
tkWinImage.$(OBJEXT) \
tkWinInit.$(OBJEXT) \
diff --git a/win/makefile.vc b/win/makefile.vc
index ee42f1e..4624265 100644
--- a/win/makefile.vc
+++ b/win/makefile.vc
@@ -189,7 +189,6 @@ TKOBJS = \
$(TMP_DIR)\tkWinEmbed.obj \
$(TMP_DIR)\tkWinFont.obj \
$(TMP_DIR)\tkWinGDI.obj \
- $(TMP_DIR)\tkWinHDC.obj \
$(TMP_DIR)\tkWinIco.obj \
$(TMP_DIR)\tkWinImage.obj \
$(TMP_DIR)\tkWinInit.obj \
diff --git a/win/tkWinHDC.c b/win/tkWinHDC.c
deleted file mode 100644
index daca149..0000000
--- a/win/tkWinHDC.c
+++ /dev/null
@@ -1,295 +0,0 @@
-/*
- * tkWinHDC.c --
- *
- * This module implements utility functions for accessing hardware device contexts
- * for graphics rendering in Windows.
- *
- * Copyright © 2009 Michael I. Schwartz.
- * Copyright © 2021 Kevin Walzer/WordTech Communications LLC.
- *
- * See the file "license.terms" for information on usage and redistribution of
- * this file, and for a DISCLAIMER OF ALL WARRANTIES.
- */
-
-
-#include "tkWinHDC.h"
-
-/*
- *----------------------------------------------------------------------
- *
- * Hdc_build_name --
- *
- * Creates HDC name.
- *
- * Results:
- * HDC name created.
- *
- *----------------------------------------------------------------------
- */
-
-static const char *Hdc_build_name(int type)
-{
- const char *prefix;
- Tcl_HashEntry *data;
- int status;
-
- if ( (data = Tcl_FindHashEntry(&hdcprefixes, (char *)type)) != 0 )
- prefix = (const char *)Tcl_GetHashValue(data);
- else
- {
- char *cp;
- prefix = "hdc";
- if ( (cp = (char *)Tcl_Alloc(4)) != 0 )
- {
- strcpy (cp, prefix);
- if ( (data = Tcl_CreateHashEntry(&hdcprefixes, (char *)type, &status)) != 0 )
- Tcl_SetHashValue(data, (ClientData)cp);
- }
- }
-
- sprintf(hdc_name, "%s%ld", prefix, ++hdc_count);
- return hdc_name;
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * hdc_create --
- *
- * Creates device context.
- *
- * Results:
- * HDC created.
- *
- *----------------------------------------------------------------------
- */
-
-const char * hdc_create (Tcl_Interp *interp, void *ptr, int type)
-{
- struct hdc_value *pval;
- const char *name;
- Tcl_HashEntry *entry;
- int status;
-
- pval = (struct hdc_value *)Tcl_Alloc(sizeof(struct hdc_value));
- if (pval == 0)
- {
- return 0;
- }
- pval->addr = ptr;
- pval->type = type;
-
- name = Hdc_build_name(type);
- if ( ( entry = Tcl_CreateHashEntry(&hdcs, name, &status)) != 0 )
- Tcl_SetHashValue(entry, (ClientData)pval);
- return name;
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * hdc_valid --
- *
- * Tests validity of HDC.
- *
- * Results:
- * HDC tested.
- *
- *----------------------------------------------------------------------
- */
-
-int hdc_valid (Tcl_Interp *interp, const char *hdcname, int type)
-{
- struct hdc_value *val;
- Tcl_HashEntry *data;
-
- if ( (data = Tcl_FindHashEntry(&hdcs, hdcname)) != 0 )
- {
- val = (struct hdc_value *)Tcl_GetHashValue(data);
-
- if ( type <= 0 || val->type == type )
- return 1;
- }
- return 0;
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * hdc_delete --
- *
- * Dletes device context.
- *
- * Results:
- * HDC created.
- *
- *----------------------------------------------------------------------
- */
-
-int hdc_delete (Tcl_Interp *interp, const char *hdcname)
-{
- struct hdc_value *val;
- Tcl_HashEntry *data;
-
- if ( (data = Tcl_FindHashEntry(&hdcs, hdcname)) != 0 )
- {
- val = (struct hdc_value *)Tcl_GetHashValue(data);
-
- Tcl_DeleteHashEntry(data);
- Tcl_Free((void *)val);
- return 1;
- }
- return 0;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * hdc_get --
- *
- * Gets device context.
- *
- * Results:
- * HDC returned.
- *
- *----------------------------------------------------------------------
- */
-
-void * hdc_get (Tcl_Interp *interp, const char *hdcname)
-{
- struct hdc_value *val;
- Tcl_HashEntry *data;
-
- if ( (data = Tcl_FindHashEntry(&hdcs, hdcname)) != 0 )
- val = (struct hdc_value *)Tcl_GetHashValue(data);
- else
- return 0;
-
- return val->addr;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * hdc_typeof --
- *
- * Gets HDC type.
- *
- * Results:
- * Type returned.
- *
- *----------------------------------------------------------------------
- */
-
-
-int hdc_typeof (Tcl_Interp *interp, const char *hdcname)
-{
- struct hdc_value *val;
- Tcl_HashEntry *data;
-
- if ( (data = Tcl_FindHashEntry(&hdcs, hdcname)) != 0 )
- val = (struct hdc_value *)Tcl_GetHashValue(data);
-
- return val->type;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * hdc_prefixof --
- *
- * Gets HDC prefix.
- *
- * Results:
- * Prefix returned.
- *
- *----------------------------------------------------------------------
- */
-
-const char * hdc_prefixof (Tcl_Interp *interp, int type, const char *newprefix)
-{
- const char *prefix;
- Tcl_HashEntry *data;
-
- if ( (data = Tcl_FindHashEntry(&hdcprefixes, (char *)type)) != 0 )
- prefix = (const char *)Tcl_GetHashValue(data);
-
- if ( newprefix )
- {
- char *cp;
- size_t siz, len;
-
- siz = strlen(newprefix);
- len = siz > 32 ? 32 : siz;
-
- if ( (cp = (char *)Tcl_Alloc(len+1)) != 0 )
- {
- int newptr = 0;
-
- strncpy (cp, newprefix, len);
- cp[len] = '\0';
- if ( data == 0 )
- data = Tcl_CreateHashEntry(&hdcprefixes,(char *)type,&newptr);
- Tcl_SetHashValue(data, (ClientData)cp);
- prefix = cp;
- }
- }
-
- return prefix;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * hdc_list --
- *
- * Lists all device contexts.
- *
- * Results:
- * List of device contexts returned.
- *
- *----------------------------------------------------------------------
- */
-
-int hdc_list (Tcl_Interp *interp, int type, const char *out[], int *poutlen)
-{
- Tcl_HashEntry *ent;
- Tcl_HashSearch srch;
- int i=0;
- const char *cp;
- int retval = 0;
- struct hdc_value *val;
-
- for ( ent = Tcl_FirstHashEntry(&hdcs, &srch); ent !=0; ent=Tcl_NextHashEntry(&srch))
- {
- if ( (cp = Tcl_GetHashKey(&hdcs, ent)) != 0 )
- {
- if ( i < *poutlen )
- {
- if ( (val = (struct hdc_value *)Tcl_GetHashValue(ent) ) != 0 )
- {
- if ( type <= 0 || type == val->type )
- {
- out[i++] = cp;
- retval++;
- }
- }
- }
- }
- }
- *poutlen = i;
- return retval;
-}
-
-/*
- * Local Variables:
- * mode: c
- * c-basic-offset: 4
- * fill-column: 78
- * End:
- */
-
-
diff --git a/win/tkWinHDC.h b/win/tkWinHDC.h
deleted file mode 100644
index c83c894..0000000
--- a/win/tkWinHDC.h
+++ /dev/null
@@ -1,29 +0,0 @@
-#include <tcl.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-
-/*
- * Static data and function prototypes.
- */
-
-struct hdc_value
-{
- void *addr;
- int type;
-};
-
-static unsigned long hdc_count = 0L;
-static Tcl_HashTable hdcs;
-static Tcl_HashTable hdcprefixes;
-static char hdc_name [32+12+1];
-
-
-const char * hdc_create (Tcl_Interp *interp, void *ptr, int type);
-int hdc_valid (Tcl_Interp *interp, const char *hdcname, int type);
-int hdc_delete (Tcl_Interp *interp, const char *hdcname);
-const char * hdc_prefixof (Tcl_Interp *interp, int type, const char *newprefix);
-int hdc_typeof (Tcl_Interp *interp, const char *hdcname);
-void * hdc_get (Tcl_Interp *interp, const char *hdcname);
-static const char *Hdc_build_name(int type); \ No newline at end of file
diff --git a/win/tkWinPrint.c b/win/tkWinPrint.c
index 2926d76..f698bb7 100644
--- a/win/tkWinPrint.c
+++ b/win/tkWinPrint.c
@@ -44,6 +44,8 @@ static int PrintOpenDoc(ClientData clientData, Tcl_Interp *interp, int argc, Tcl
static int PrintCloseDoc(ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *const objv[]);
static int PrintOpenPage(ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *const objv[]);
static int PrintClosePage(ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *const objv[]);
+int PrintGetHDC(ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *const objv[]);
+HDC get_hdc(void);
int Winprint_Init(Tcl_Interp * interp);
/*----------------------------------------------------------------------
@@ -327,6 +329,54 @@ int PrintClosePage(ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj
/*
* --------------------------------------------------------------------------
*
+ * PrintGetHDC--
+ *
+ * Gets the device context for the printer.
+ *
+ * Results:
+ * Returns HDC.
+ *
+ * -------------------------------------------------------------------------
+ */
+
+int PrintGetHDC(ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *const objv[])
+{
+
+ (void) clientData;
+ (void) argc;
+ (void) objv;
+
+ if ( hDC == NULL) {
+ return TCL_ERROR;
+ }
+
+ get_hdc();
+ return TCL_OK;
+}
+
+/*
+ * --------------------------------------------------------------------------
+ *
+ * PrintGetHDC--
+ *
+ * Gets the device context for the printer.
+ *
+ * Results:
+ * Returns HDC.
+ *
+ * -------------------------------------------------------------------------
+ */
+
+
+HDC get_hdc(void) {
+
+ return hDC;
+
+}
+
+/*
+ * --------------------------------------------------------------------------
+ *
* Winprint_Init--
*
* Initializes printing module on Windows.
@@ -336,6 +386,7 @@ int PrintClosePage(ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj
*
* -------------------------------------------------------------------------
*/
+
int Winprint_Init(Tcl_Interp * interp)
{
Tcl_CreateObjCommand(interp, "::tk::print::_selectprinter", PrintSelectPrinter, NULL, NULL);
@@ -344,7 +395,8 @@ int Winprint_Init(Tcl_Interp * interp)
Tcl_CreateObjCommand(interp, "::tk::print::_opendoc", PrintOpenDoc, NULL, NULL);
Tcl_CreateObjCommand(interp, "::tk::print::_closedoc", PrintCloseDoc, NULL, NULL);
Tcl_CreateObjCommand(interp, "::tk::print::_openpage", PrintOpenPage, NULL, NULL);
- Tcl_CreateObjCommand(interp, "::tk::print::_closepage", PrintClosePage, NULL, NULL);
+ Tcl_CreateObjCommand(interp, "::tk::print::_closepage", PrintClosePage, NULL, NULL);
+ Tcl_CreateObjCommand(interp, "::tk::print::_gethdc", PrintGetHDC, NULL, NULL);
return TCL_OK;
}