Alexei Podtelezhnikov pushed to branch master at FreeType / FreeType
Commits:
-
bb33f03a
by Vincent Torri at 2021-01-27T06:43:41-05:00
7 changed files:
- CMakeLists.txt
- ChangeLog
- builds/unix/configure.raw
- + builds/windows/ftsystem.c
- builds/windows/vc2010/freetype.vcxproj
- builds/windows/visualc/freetype.vcproj
- meson.build
Changes:
... | ... | @@ -358,6 +358,8 @@ set(BASE_SRCS |
358 | 358 |
|
359 | 359 |
if (UNIX)
|
360 | 360 |
list(APPEND BASE_SRCS "builds/unix/ftsystem.c")
|
361 |
+elseif (WIN32)
|
|
362 |
+ list(APPEND BASE_SRCS "builds/windows/ftsystem.c")
|
|
361 | 363 |
else ()
|
362 | 364 |
list(APPEND BASE_SRCS "src/base/ftsystem.c")
|
363 | 365 |
endif ()
|
1 |
+2021-01-27 Vincent Torri <vincent.torri@gmail.com>
|
|
2 |
+ |
|
3 |
+ * builds/windows/ftsystem.c: Add shared memory support on Windows.
|
|
4 |
+ |
|
1 | 5 |
2021-01-23 Werner Lemberg <wl@gnu.org>
|
2 | 6 |
|
3 | 7 |
Require HarfBuzz 2.0.0.
|
... | ... | @@ -202,7 +202,13 @@ if test "x${enable_mmap}" != "xno"; then |
202 | 202 |
fi
|
203 | 203 |
if test "x${enable_mmap}" = "xno" \
|
204 | 204 |
-o "$ac_cv_func_mmap_fixed_mapped" != "yes"; then
|
205 |
- FTSYS_SRC='$(BASE_DIR)/ftsystem.c'
|
|
205 |
+ case
|
|
206 |
+ *-*-mingw*)
|
|
207 |
+ FTSYS_SRC='$(PLATFORM_DIR)/ftsystem.c'
|
|
208 |
+ ;;
|
|
209 |
+ *)
|
|
210 |
+ FTSYS_SRC='$(BASE_DIR)/ftsystem.c'
|
|
211 |
+ esac
|
|
206 | 212 |
else
|
207 | 213 |
FTSYS_SRC='$(PLATFORM_DIR)/ftsystem.c'
|
208 | 214 |
|
1 |
+/***************************************************************************/
|
|
2 |
+/* */
|
|
3 |
+/* ftsystem.c */
|
|
4 |
+/* */
|
|
5 |
+/* Unix-specific FreeType low-level system interface (body). */
|
|
6 |
+/* */
|
|
7 |
+/* Copyright (C) 1996-2020 by */
|
|
8 |
+/* David Turner, Robert Wilhelm, and Werner Lemberg. */
|
|
9 |
+/* */
|
|
10 |
+/* This file is part of the FreeType project, and may only be used, */
|
|
11 |
+/* modified, and distributed under the terms of the FreeType project */
|
|
12 |
+/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
|
|
13 |
+/* this file you indicate that you have read the license and */
|
|
14 |
+/* understand and accept it fully. */
|
|
15 |
+/* */
|
|
16 |
+/***************************************************************************/
|
|
17 |
+ |
|
18 |
+ |
|
19 |
+#include <ft2build.h>
|
|
20 |
+ /* we use our special ftconfig.h file, not the standard one */
|
|
21 |
+#include FT_CONFIG_CONFIG_H
|
|
22 |
+#include <freetype/internal/ftdebug.h>
|
|
23 |
+#include <freetype/ftsystem.h>
|
|
24 |
+#include <freetype/fterrors.h>
|
|
25 |
+#include <freetype/fttypes.h>
|
|
26 |
+#include <freetype/internal/ftstream.h>
|
|
27 |
+ |
|
28 |
+ /* memory-mapping includes and definitions */
|
|
29 |
+#include <windows.h>
|
|
30 |
+ |
|
31 |
+#include <stdlib.h>
|
|
32 |
+ |
|
33 |
+ |
|
34 |
+ /*************************************************************************/
|
|
35 |
+ /* */
|
|
36 |
+ /* MEMORY MANAGEMENT INTERFACE */
|
|
37 |
+ /* */
|
|
38 |
+ /*************************************************************************/
|
|
39 |
+ |
|
40 |
+ |
|
41 |
+ /*************************************************************************/
|
|
42 |
+ /* */
|
|
43 |
+ /* <Function> */
|
|
44 |
+ /* ft_alloc */
|
|
45 |
+ /* */
|
|
46 |
+ /* <Description> */
|
|
47 |
+ /* The memory allocation function. */
|
|
48 |
+ /* */
|
|
49 |
+ /* <Input> */
|
|
50 |
+ /* memory :: A pointer to the memory object. */
|
|
51 |
+ /* */
|
|
52 |
+ /* size :: The requested size in bytes. */
|
|
53 |
+ /* */
|
|
54 |
+ /* <Return> */
|
|
55 |
+ /* The address of newly allocated block. */
|
|
56 |
+ /* */
|
|
57 |
+ FT_CALLBACK_DEF( void* )
|
|
58 |
+ ft_alloc( FT_Memory memory,
|
|
59 |
+ long size )
|
|
60 |
+ {
|
|
61 |
+ FT_UNUSED( memory );
|
|
62 |
+ |
|
63 |
+ return malloc( size );
|
|
64 |
+ }
|
|
65 |
+ |
|
66 |
+ |
|
67 |
+ /*************************************************************************/
|
|
68 |
+ /* */
|
|
69 |
+ /* <Function> */
|
|
70 |
+ /* ft_realloc */
|
|
71 |
+ /* */
|
|
72 |
+ /* <Description> */
|
|
73 |
+ /* The memory reallocation function. */
|
|
74 |
+ /* */
|
|
75 |
+ /* <Input> */
|
|
76 |
+ /* memory :: A pointer to the memory object. */
|
|
77 |
+ /* */
|
|
78 |
+ /* cur_size :: The current size of the allocated memory block. */
|
|
79 |
+ /* */
|
|
80 |
+ /* new_size :: The newly requested size in bytes. */
|
|
81 |
+ /* */
|
|
82 |
+ /* block :: The current address of the block in memory. */
|
|
83 |
+ /* */
|
|
84 |
+ /* <Return> */
|
|
85 |
+ /* The address of the reallocated memory block. */
|
|
86 |
+ /* */
|
|
87 |
+ FT_CALLBACK_DEF( void* )
|
|
88 |
+ ft_realloc( FT_Memory memory,
|
|
89 |
+ long cur_size,
|
|
90 |
+ long new_size,
|
|
91 |
+ void* block )
|
|
92 |
+ {
|
|
93 |
+ FT_UNUSED( memory );
|
|
94 |
+ FT_UNUSED( cur_size );
|
|
95 |
+ |
|
96 |
+ return realloc( block, new_size );
|
|
97 |
+ }
|
|
98 |
+ |
|
99 |
+ |
|
100 |
+ /*************************************************************************/
|
|
101 |
+ /* */
|
|
102 |
+ /* <Function> */
|
|
103 |
+ /* ft_free */
|
|
104 |
+ /* */
|
|
105 |
+ /* <Description> */
|
|
106 |
+ /* The memory release function. */
|
|
107 |
+ /* */
|
|
108 |
+ /* <Input> */
|
|
109 |
+ /* memory :: A pointer to the memory object. */
|
|
110 |
+ /* */
|
|
111 |
+ /* block :: The address of block in memory to be freed. */
|
|
112 |
+ /* */
|
|
113 |
+ FT_CALLBACK_DEF( void )
|
|
114 |
+ ft_free( FT_Memory memory,
|
|
115 |
+ void* block )
|
|
116 |
+ {
|
|
117 |
+ FT_UNUSED( memory );
|
|
118 |
+ |
|
119 |
+ free( block );
|
|
120 |
+ }
|
|
121 |
+ |
|
122 |
+ |
|
123 |
+ /*************************************************************************/
|
|
124 |
+ /* */
|
|
125 |
+ /* RESOURCE MANAGEMENT INTERFACE */
|
|
126 |
+ /* */
|
|
127 |
+ /*************************************************************************/
|
|
128 |
+ |
|
129 |
+ |
|
130 |
+ /*************************************************************************/
|
|
131 |
+ /* */
|
|
132 |
+ /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
|
|
133 |
+ /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
|
|
134 |
+ /* messages during execution. */
|
|
135 |
+ /* */
|
|
136 |
+#undef FT_COMPONENT
|
|
137 |
+#define FT_COMPONENT io
|
|
138 |
+ |
|
139 |
+ /* We use the macro STREAM_FILE for convenience to extract the */
|
|
140 |
+ /* system-specific stream handle from a given FreeType stream object */
|
|
141 |
+#define STREAM_FILE( stream ) ( (FILE*)stream->descriptor.pointer )
|
|
142 |
+ |
|
143 |
+ |
|
144 |
+ /*************************************************************************/
|
|
145 |
+ /* */
|
|
146 |
+ /* <Function> */
|
|
147 |
+ /* ft_close_stream_by_munmap */
|
|
148 |
+ /* */
|
|
149 |
+ /* <Description> */
|
|
150 |
+ /* The function to close a stream which is opened by mmap. */
|
|
151 |
+ /* */
|
|
152 |
+ /* <Input> */
|
|
153 |
+ /* stream :: A pointer to the stream object. */
|
|
154 |
+ /* */
|
|
155 |
+ FT_CALLBACK_DEF( void )
|
|
156 |
+ ft_close_stream_by_munmap( FT_Stream stream )
|
|
157 |
+ {
|
|
158 |
+ UnmapViewOfFile( (LPCVOID)stream->descriptor.pointer );
|
|
159 |
+ |
|
160 |
+ stream->descriptor.pointer = NULL;
|
|
161 |
+ stream->size = 0;
|
|
162 |
+ stream->base = 0;
|
|
163 |
+ }
|
|
164 |
+ |
|
165 |
+ |
|
166 |
+ /*************************************************************************/
|
|
167 |
+ /* */
|
|
168 |
+ /* <Function> */
|
|
169 |
+ /* ft_close_stream_by_free */
|
|
170 |
+ /* */
|
|
171 |
+ /* <Description> */
|
|
172 |
+ /* The function to close a stream which is created by ft_alloc. */
|
|
173 |
+ /* */
|
|
174 |
+ /* <Input> */
|
|
175 |
+ /* stream :: A pointer to the stream object. */
|
|
176 |
+ /* */
|
|
177 |
+ FT_CALLBACK_DEF( void )
|
|
178 |
+ ft_close_stream_by_free( FT_Stream stream )
|
|
179 |
+ {
|
|
180 |
+ ft_free( NULL, stream->descriptor.pointer );
|
|
181 |
+ |
|
182 |
+ stream->descriptor.pointer = NULL;
|
|
183 |
+ stream->size = 0;
|
|
184 |
+ stream->base = 0;
|
|
185 |
+ }
|
|
186 |
+ |
|
187 |
+ |
|
188 |
+ /* documentation is in ftobjs.h */
|
|
189 |
+ |
|
190 |
+ FT_BASE_DEF( FT_Error )
|
|
191 |
+ FT_Stream_Open( FT_Stream stream,
|
|
192 |
+ const char* filepathname )
|
|
193 |
+ {
|
|
194 |
+ HANDLE file;
|
|
195 |
+ HANDLE fm;
|
|
196 |
+ LARGE_INTEGER size;
|
|
197 |
+ |
|
198 |
+ if ( !stream )
|
|
199 |
+ return FT_THROW( Invalid_Stream_Handle );
|
|
200 |
+ |
|
201 |
+ /* open the file */
|
|
202 |
+ file = CreateFileA( filepathname, GENERIC_READ, FILE_SHARE_READ, NULL,
|
|
203 |
+ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
|
|
204 |
+ if (file == INVALID_HANDLE_VALUE)
|
|
205 |
+ {
|
|
206 |
+ FT_ERROR(( "FT_Stream_Open:" ));
|
|
207 |
+ FT_ERROR(( " could not open `%s'\n", filepathname ));
|
|
208 |
+ return FT_THROW( Cannot_Open_Resource );
|
|
209 |
+ }
|
|
210 |
+ |
|
211 |
+ if ( GetFileSizeEx(file, &size) == FALSE )
|
|
212 |
+ {
|
|
213 |
+ FT_ERROR(( "FT_Stream_Open:" ));
|
|
214 |
+ FT_ERROR(( " could not retrieve size of file `%s'\n", filepathname ));
|
|
215 |
+ goto Fail_Open;
|
|
216 |
+ }
|
|
217 |
+ |
|
218 |
+ /* `stream->size' is typedef'd to unsigned long (in `ftsystem.h'); */
|
|
219 |
+ /* So avoid overflow caused by fonts in huge files larger than */
|
|
220 |
+ /* 2GB, do a test. */
|
|
221 |
+ if ( size.QuadPart > LONG_MAX )
|
|
222 |
+ {
|
|
223 |
+ FT_ERROR(( "FT_Stream_Open: file is too big\n" ));
|
|
224 |
+ goto Fail_Open;
|
|
225 |
+ }
|
|
226 |
+ else if ( size.QuadPart == 0 )
|
|
227 |
+ {
|
|
228 |
+ FT_ERROR(( "FT_Stream_Open: zero-length file\n" ));
|
|
229 |
+ goto Fail_Open;
|
|
230 |
+ }
|
|
231 |
+ |
|
232 |
+ fm = CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL);
|
|
233 |
+ if (fm == NULL)
|
|
234 |
+ {
|
|
235 |
+ FT_ERROR(( "FT_Stream_Open: can not map file\n" ));
|
|
236 |
+ goto Fail_Open;
|
|
237 |
+ }
|
|
238 |
+ |
|
239 |
+ /* Store only the low part of this 64 bits integer because long is */
|
|
240 |
+ /* a 32 bits type. Anyway, a check has been done above to forbid */
|
|
241 |
+ /* a size greater than LONG_MAX */
|
|
242 |
+ stream->size = size.LowPart;
|
|
243 |
+ stream->pos = 0;
|
|
244 |
+ stream->base = (unsigned char *)MapViewOfFile(fm, FILE_MAP_READ, 0, 0, 0);
|
|
245 |
+ |
|
246 |
+ CloseHandle(fm);
|
|
247 |
+ if ( stream->base != NULL )
|
|
248 |
+ stream->close = ft_close_stream_by_munmap;
|
|
249 |
+ else
|
|
250 |
+ {
|
|
251 |
+ DWORD total_read_count;
|
|
252 |
+ |
|
253 |
+ FT_ERROR(( "FT_Stream_Open:" ));
|
|
254 |
+ FT_ERROR(( " could not `mmap' file `%s'\n", filepathname ));
|
|
255 |
+ |
|
256 |
+ stream->base = (unsigned char*)ft_alloc( NULL, stream->size );
|
|
257 |
+ |
|
258 |
+ if ( !stream->base )
|
|
259 |
+ {
|
|
260 |
+ FT_ERROR(( "FT_Stream_Open:" ));
|
|
261 |
+ FT_ERROR(( " could not `alloc' memory\n" ));
|
|
262 |
+ goto Fail_Map;
|
|
263 |
+ }
|
|
264 |
+ |
|
265 |
+ total_read_count = 0;
|
|
266 |
+ do
|
|
267 |
+ {
|
|
268 |
+ DWORD read_count;
|
|
269 |
+ |
|
270 |
+ if ( ReadFile( file,
|
|
271 |
+ stream->base + total_read_count,
|
|
272 |
+ stream->size - total_read_count,
|
|
273 |
+ &read_count, NULL ) == FALSE )
|
|
274 |
+ {
|
|
275 |
+ FT_ERROR(( "FT_Stream_Open:" ));
|
|
276 |
+ FT_ERROR(( " error while `read'ing file `%s'\n", filepathname ));
|
|
277 |
+ goto Fail_Read;
|
|
278 |
+ }
|
|
279 |
+ |
|
280 |
+ total_read_count += read_count;
|
|
281 |
+ |
|
282 |
+ } while ( total_read_count != stream->size );
|
|
283 |
+ |
|
284 |
+ stream->close = ft_close_stream_by_free;
|
|
285 |
+ }
|
|
286 |
+ |
|
287 |
+ CloseHandle( file );
|
|
288 |
+ |
|
289 |
+ stream->descriptor.pointer = stream->base;
|
|
290 |
+ stream->pathname.pointer = (char*)filepathname;
|
|
291 |
+ |
|
292 |
+ stream->read = 0;
|
|
293 |
+ |
|
294 |
+ FT_TRACE1(( "FT_Stream_Open:" ));
|
|
295 |
+ FT_TRACE1(( " opened `%s' (%ld bytes) successfully\n",
|
|
296 |
+ filepathname, stream->size ));
|
|
297 |
+ |
|
298 |
+ return FT_Err_Ok;
|
|
299 |
+ |
|
300 |
+ Fail_Read:
|
|
301 |
+ ft_free( NULL, stream->base );
|
|
302 |
+ |
|
303 |
+ Fail_Map:
|
|
304 |
+ CloseHandle( file );
|
|
305 |
+ |
|
306 |
+ Fail_Open:
|
|
307 |
+ CloseHandle( file );
|
|
308 |
+ |
|
309 |
+ stream->base = NULL;
|
|
310 |
+ stream->size = 0;
|
|
311 |
+ stream->pos = 0;
|
|
312 |
+ |
|
313 |
+ return FT_THROW( Cannot_Open_Stream );
|
|
314 |
+ }
|
|
315 |
+ |
|
316 |
+ |
|
317 |
+#ifdef FT_DEBUG_MEMORY
|
|
318 |
+ |
|
319 |
+ extern FT_Int
|
|
320 |
+ ft_mem_debug_init( FT_Memory memory );
|
|
321 |
+ |
|
322 |
+ extern void
|
|
323 |
+ ft_mem_debug_done( FT_Memory memory );
|
|
324 |
+ |
|
325 |
+#endif
|
|
326 |
+ |
|
327 |
+ |
|
328 |
+ /* documentation is in ftobjs.h */
|
|
329 |
+ |
|
330 |
+ FT_BASE_DEF( FT_Memory )
|
|
331 |
+ FT_New_Memory( void )
|
|
332 |
+ {
|
|
333 |
+ FT_Memory memory;
|
|
334 |
+ |
|
335 |
+ |
|
336 |
+ memory = (FT_Memory)malloc( sizeof ( *memory ) );
|
|
337 |
+ if ( memory )
|
|
338 |
+ {
|
|
339 |
+ memory->user = 0;
|
|
340 |
+ memory->alloc = ft_alloc;
|
|
341 |
+ memory->realloc = ft_realloc;
|
|
342 |
+ memory->free = ft_free;
|
|
343 |
+#ifdef FT_DEBUG_MEMORY
|
|
344 |
+ ft_mem_debug_init( memory );
|
|
345 |
+#endif
|
|
346 |
+ }
|
|
347 |
+ |
|
348 |
+ return memory;
|
|
349 |
+ }
|
|
350 |
+ |
|
351 |
+ |
|
352 |
+ /* documentation is in ftobjs.h */
|
|
353 |
+ |
|
354 |
+ FT_BASE_DEF( void )
|
|
355 |
+ FT_Done_Memory( FT_Memory memory )
|
|
356 |
+ {
|
|
357 |
+#ifdef FT_DEBUG_MEMORY
|
|
358 |
+ ft_mem_debug_done( memory );
|
|
359 |
+#endif
|
|
360 |
+ memory->free( memory, memory );
|
|
361 |
+ }
|
|
362 |
+ |
|
363 |
+ |
|
364 |
+/* END */
|
... | ... | @@ -328,7 +328,6 @@ |
328 | 328 |
<ClCompile Include="..\..\..\src\base\ftpfr.c" />
|
329 | 329 |
<ClCompile Include="..\..\..\src\base\ftstroke.c" />
|
330 | 330 |
<ClCompile Include="..\..\..\src\base\ftsynth.c" />
|
331 |
- <ClCompile Include="..\..\..\src\base\ftsystem.c" />
|
|
332 | 331 |
<ClCompile Include="..\..\..\src\base\fttype1.c" />
|
333 | 332 |
<ClCompile Include="..\..\..\src\base\ftwinfnt.c" />
|
334 | 333 |
<ClCompile Include="..\..\..\src\bdf\bdf.c" />
|
... | ... | @@ -354,6 +353,9 @@ |
354 | 353 |
<ClCompile Include="..\ftdebug.c">
|
355 | 354 |
<DisableLanguageExtensions>false</DisableLanguageExtensions>
|
356 | 355 |
</ClCompile>
|
356 |
+ <ClCompile Include="..\ftsystem.c">
|
|
357 |
+ <DisableLanguageExtensions>false</DisableLanguageExtensions>
|
|
358 |
+ </ClCompile>
|
|
357 | 359 |
<ResourceCompile Include="..\..\..\src\base\ftver.rc" />
|
358 | 360 |
</ItemGroup>
|
359 | 361 |
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
... | ... | @@ -395,8 +395,40 @@ |
395 | 395 |
>
|
396 | 396 |
</File>
|
397 | 397 |
<File
|
398 |
- RelativePath="..\..\..\src\base\ftsystem.c"
|
|
398 |
+ RelativePath="..\ftsystem.c"
|
|
399 | 399 |
>
|
400 |
+ <FileConfiguration
|
|
401 |
+ Name="Release|Win32"
|
|
402 |
+ >
|
|
403 |
+ <Tool
|
|
404 |
+ Name="VCCLCompilerTool"
|
|
405 |
+ DisableLanguageExtensions="false"
|
|
406 |
+ />
|
|
407 |
+ </FileConfiguration>
|
|
408 |
+ <FileConfiguration
|
|
409 |
+ Name="Release Static|Win32"
|
|
410 |
+ >
|
|
411 |
+ <Tool
|
|
412 |
+ Name="VCCLCompilerTool"
|
|
413 |
+ DisableLanguageExtensions="false"
|
|
414 |
+ />
|
|
415 |
+ </FileConfiguration>
|
|
416 |
+ <FileConfiguration
|
|
417 |
+ Name="Debug|Win32"
|
|
418 |
+ >
|
|
419 |
+ <Tool
|
|
420 |
+ Name="VCCLCompilerTool"
|
|
421 |
+ DisableLanguageExtensions="false"
|
|
422 |
+ />
|
|
423 |
+ </FileConfiguration>
|
|
424 |
+ <FileConfiguration
|
|
425 |
+ Name="Debug Static|Win32"
|
|
426 |
+ >
|
|
427 |
+ <Tool
|
|
428 |
+ Name="VCCLCompilerTool"
|
|
429 |
+ DisableLanguageExtensions="false"
|
|
430 |
+ />
|
|
431 |
+ </FileConfiguration>
|
|
400 | 432 |
</File>
|
401 | 433 |
<File
|
402 | 434 |
RelativePath="..\..\..\src\smooth\smooth.c"
|
... | ... | @@ -201,6 +201,8 @@ endif |
201 | 201 |
if use_mmap
|
202 | 202 |
# This version of ftsystem.c uses mmap() to read input font files.
|
203 | 203 |
ft2_sources += files(['builds/unix/ftsystem.c',])
|
204 |
+elif host_machine.system() == 'windows'
|
|
205 |
+ ft2_sources += files(['builds/windows/ftsystem.c',])
|
|
204 | 206 |
else
|
205 | 207 |
ft2_sources += files(['src/base/ftsystem.c',])
|
206 | 208 |
endif
|