Tk-Components

Check-in [68ffd5ad23]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add support for Windows
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:68ffd5ad23392c0ba3fef7734d8ccfbf35b2af45
User & Date: kevin 2015-09-12 02:32:58
Context
2015-09-12
02:33
Add support for Windows check-in: aa75f150a4 user: kevin tags: trunk
02:32
Add support for Windows check-in: 68ffd5ad23 user: kevin tags: trunk
2015-07-23
01:33
Add documentation for aem; ready for 1.0 release check-in: 24d8673482 user: kevin tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to customfont/configure.in.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
67
68
69
70
71
72
73
74

75
76
77
78

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98













99
100
101
102
103
104
105
106
107
108








109
110
111
112
113
114
115
# Set your package name and version numbers here.
#
# This initializes the environment with PACKAGE_NAME and PACKAGE_VERSION
# set as provided.  These will also be added as -D defs in your Makefile
# so you can encode the package version directly into the source files.
#-----------------------------------------------------------------------

AC_INIT([customfont], [1.0])

if test "`uname -s`" != "Darwin" -o \
	"`uname -r | awk -F. '{print [$]1}'`" -lt 9; then
    AC_MSG_ERROR([Mac OS X 10.5 or later required!])
fi

#--------------------------------------------------------------------
................................................................................
# public headers that need to be installed in TEA_ADD_HEADERS,
# stub library C source files to compile in TEA_ADD_STUB_SOURCES,
# and runtime Tcl library files in TEA_ADD_TCL_SOURCES.
# This defines PKG(_STUB)_SOURCES, PKG(_STUB)_OBJECTS, PKG_HEADERS
# and PKG_TCL_SOURCES.
#-----------------------------------------------------------------------

TEA_ADD_SOURCES([macosx/customfont.c])

TEA_ADD_HEADERS([])
TEA_ADD_INCLUDES([])
TEA_ADD_LIBS([-framework Cocoa -framework CoreFoundation -framework CoreServices])
TEA_ADD_CFLAGS([-std=gnu99 -fobjc-gc])

TEA_ADD_STUB_SOURCES([])

#--------------------------------------------------------------------
# __CHANGE__
# A few miscellaneous platform-specific items:
#
# Define a special symbol for Windows (BUILD_tkWebView in this case) so
# that we create the export library with the dll.
#
# Windows creates a few extra files that need to be cleaned up.
# You can add more files to clean if your extension creates any extra
# files.
#
# TEA_ADD_* any platform specific compiler/build info here.
#--------------------------------------------------------------------

# Add pkgIndex.tcl if it is generated in the Makefile instead of ./configure
# and change Makefile.in to move it from CONFIG_CLEAN_FILES to BINARIES var.
#CLEANFILES="pkgIndex.tcl"
if test "${TEA_PLATFORM}" = "windows" ; then













    AC_DEFINE(BUILD_tkWebView, 1, [Build windows export dll])
    CLEANFILES="$CLEANFILES *.lib *.dll *.exp *.ilk *.pdb vc*.pch"
    #TEA_ADD_SOURCES([win/winFile.c])
    #TEA_ADD_INCLUDES([-I\"$(${CYGPATH} ${srcdir}/win)\"])
else
    # Ensure no empty else clauses
    :
    #TEA_ADD_SOURCES([unix/unixFile.c])
    #TEA_ADD_LIBS([-lsuperfly])
fi








AC_SUBST(CLEANFILES)

#--------------------------------------------------------------------
# __CHANGE__
# Choose which headers you need.  Extension authors should try very
# hard to only rely on the Tcl public header files.  Internal headers
# contain private data structures and are subject to change without







|







 







<
>


<
<
>






|








<
<
<
<

>
>
>
>
>
>
>
>
>
>
>
>
>
|
|



|
<



>
>
>
>
>
>
>
>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
67
68
69
70
71
72
73

74
75
76


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92




93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Set your package name and version numbers here.
#
# This initializes the environment with PACKAGE_NAME and PACKAGE_VERSION
# set as provided.  These will also be added as -D defs in your Makefile
# so you can encode the package version directly into the source files.
#-----------------------------------------------------------------------

AC_INIT([customfont], [1.1])

if test "`uname -s`" != "Darwin" -o \
	"`uname -r | awk -F. '{print [$]1}'`" -lt 9; then
    AC_MSG_ERROR([Mac OS X 10.5 or later required!])
fi

#--------------------------------------------------------------------
................................................................................
# public headers that need to be installed in TEA_ADD_HEADERS,
# stub library C source files to compile in TEA_ADD_STUB_SOURCES,
# and runtime Tcl library files in TEA_ADD_TCL_SOURCES.
# This defines PKG(_STUB)_SOURCES, PKG(_STUB)_OBJECTS, PKG_HEADERS
# and PKG_TCL_SOURCES.
#-----------------------------------------------------------------------



TEA_ADD_HEADERS([])
TEA_ADD_INCLUDES([])



TEA_ADD_STUB_SOURCES([])

#--------------------------------------------------------------------
# __CHANGE__
# A few miscellaneous platform-specific items:
#
# Define a special symbol for Windows (BUILD_customfont in this case) so
# that we create the export library with the dll.
#
# Windows creates a few extra files that need to be cleaned up.
# You can add more files to clean if your extension creates any extra
# files.
#
# TEA_ADD_* any platform specific compiler/build info here.
#--------------------------------------------------------------------




if test "${TEA_PLATFORM}" = "windows" ; then
    AC_PROG_CXX
    CC=$CXX
    TEA_ADD_CFLAGS([-DUNICODE -D_UNICODE])
    TEA_ADD_SOURCES([win/customfont.c])
    TEA_ADD_LIBS(kernel32.lib user32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib gdi32.lib)

    ## Check if the compiler accepts -static-libstdc++...
    AC_CACHE_CHECK([if the compiler understands -static-libstdc++],
        tcl_cv_cc_staticlib, [
        hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -static-libstdc++"
        AC_TRY_COMPILE(,, tcl_cv_cc_staticlib=yes, tcl_cv_cc_staticlib=no)
        CFLAGS=$hold_cflags])

    AC_DEFINE(BUILD_tkdnd, 1, [Build windows export dll])
    CLEANFILES="pkgIndex.tcl *.lib *.dll *.exp *.ilk *.pdb vc*.pch"
    #TEA_ADD_SOURCES([win/winFile.c])
    #TEA_ADD_INCLUDES([-I\"$(${CYGPATH} ${srcdir}/win)\"])
else
    CLEANFILES="pkgIndex.tcl"

    #TEA_ADD_SOURCES([unix/unixFile.c])
    #TEA_ADD_LIBS([-lsuperfly])
fi


if test "${TEA_WINDOWINGSYSTEM}" = "aqua"; then
	TEA_ADD_SOURCES([macosx/customfont.c])
	TEA_ADD_LIBS([-framework Cocoa -framework CoreFoundation -framework CoreServices])
	TEA_ADD_CFLAGS([-std=gnu99 -fobjc-gc])
fi

AC_SUBST(CLEANFILES)

#--------------------------------------------------------------------
# __CHANGE__
# Choose which headers you need.  Extension authors should try very
# hard to only rely on the Tcl public header files.  Internal headers
# contain private data structures and are subject to change without

Changes to customfont/pkgIndex.tcl.in.

1
2
3
4
5
6
7
#
# Tcl package index file
#
package ifneeded @PACKAGE_NAME@ @PACKAGE_VERSION@ "
    package require Tk 8.5-
    if {\"AppKit\" ni \[winfo server .\]} {error {TkAqua Cocoa required}}
        load [list ][file join $dir @PKG_LIB_FILE@] @PACKAGE_NAME@"




|
<
|
1
2
3
4
5

6
#
# Tcl package index file
#
package ifneeded @PACKAGE_NAME@ @PACKAGE_VERSION@ "
    package require Tk 8.5

        load [list [file join $dir @PKG_LIB_FILE@] @PACKAGE_NAME@]"

Added customfont/win/customfont.c.















































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * customfont.c --
 * Loads custom font file. 
 * Copyright (c) 2013 Kevin Walzer/WordTech Communications LLC.
 * Windows code based on example by Pat Thoyts:
 *  http://code.activestate.com/lists/tcl-core/8158/
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 */

#include <tcl.h>
#include <tk.h>
#include <windows.h>

/*Tcl function to add the font.*/
int AddFontResource(ClientData cd, Tcl_Interp *ip, int objc, Tcl_Obj *CONST objv[]) {

  if(objc != 2) {
    Tcl_WrongNumArgs(ip, 1, objv, "fontfile");
    return TCL_ERROR;
  }
  
  Tcl_DString ds;
  Tcl_Encoding unicode;
  int len, r = TCL_OK;
	
  const char *path = Tcl_GetString(objv[1]);
  len = strlen(path);
	  
  Tcl_DStringInit(&ds);
  unicode = Tcl_GetEncoding(interp, "unicode");
  Tcl_UtfToExternalDString(unicode, path, len, &ds);
  if (AddFontResourceExW(Tcl_DStringValue(&ds), FR_PRIVATE, NULL)
      == 0) {
    r = TCL_ERROR;
  }
  Tcl_DStringFree(&ds);
  Tcl_FreeEncoding(unicode);
  return r;
}



/*Initalize the package in the tcl interpreter, create Tcl commands. */
int Customfont_Init (Tcl_Interp *interp) {

 
  if (Tcl_InitStubs(interp, "8.5", 0) == NULL) {
    return TCL_ERROR;  
  }
  if (Tk_InitStubs(interp, "8.5", 0) == NULL) {
    return TCL_ERROR;
  }


  Tcl_CreateObjCommand(interp, "::customfont::addcustomfont", AddFontResource,(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);


  if (Tcl_PkgProvide(interp, "customfont", "1.1") != TCL_OK) {
    return TCL_ERROR;
  }
      
  return TCL_OK;
	
}

int Customfont_SafeInit(Tcl_Interp *interp) {
  return Customfont_Init(interp);
}