parent
ede84ffa42
commit
058b1260ad
3 changed files with 82 additions and 67 deletions
@ -1,82 +1,91 @@ |
|||||||
#include <sys/types.h> |
/*
|
||||||
#include <sys/stat.h> |
* Copyright © 2010 Behdad Esfahbod |
||||||
#include <sys/mman.h> |
* Copyright © 2011,2012 Google, Inc. |
||||||
#include <fcntl.h> |
* |
||||||
#include <stdlib.h> |
* This is part of HarfBuzz, a text shaping library. |
||||||
#include <stdio.h> |
* |
||||||
#include <unistd.h> |
* Permission is hereby granted, without written agreement and without |
||||||
|
* license or royalty fees, to use, copy, modify, and distribute this |
||||||
|
* software and its documentation for any purpose, provided that the |
||||||
|
* above copyright notice and the following two paragraphs appear in |
||||||
|
* all copies of this software. |
||||||
|
* |
||||||
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
||||||
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
||||||
|
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
||||||
|
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
||||||
|
* DAMAGE. |
||||||
|
* |
||||||
|
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
||||||
|
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
||||||
|
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
||||||
|
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
||||||
|
* |
||||||
|
* Google Author(s): Garret Rieger, Rod Sheeter |
||||||
|
*/ |
||||||
|
|
||||||
#include "hb-private.hh" |
#include "main-font-text.hh" |
||||||
#include "hb-blob.h" |
|
||||||
|
|
||||||
int |
/*
|
||||||
main (int argc, char **argv) |
* Command line interface to the harfbuzz font subsetter. |
||||||
{ |
*/ |
||||||
int exit_code = 0; |
|
||||||
|
|
||||||
if (argc != 4) { |
struct subset_consumer_t |
||||||
fprintf(stderr, "Must have 4 args\n"); |
{ |
||||||
exit(1); |
subset_consumer_t (option_parser_t *parser) |
||||||
} |
: failed (false), options(parser) {} |
||||||
|
|
||||||
int fd = open(argv[1], O_RDONLY); |
void init (hb_buffer_t *buffer_, |
||||||
if (fd == -1) { |
const font_options_t *font_opts) |
||||||
perror("Unable to open font file"); |
{ |
||||||
exit(1); |
font = hb_font_reference (font_opts->get_font ()); |
||||||
} |
} |
||||||
|
|
||||||
void *mapped_file = MAP_FAILED; |
void consume_line (const char *text, |
||||||
int fd_out = -1; |
unsigned int text_len, |
||||||
|
const char *text_before, |
||||||
struct stat stat; |
const char *text_after) |
||||||
if (fstat(fd, &stat) != -1) { |
{ |
||||||
|
|
||||||
mapped_file = mmap(NULL, stat.st_size, PROT_READ, MAP_PRIVATE, fd, 0); |
|
||||||
if (mapped_file == MAP_FAILED) { |
|
||||||
perror("Failed to map file"); |
|
||||||
} |
|
||||||
} else { |
|
||||||
perror("Unable to fstat"); |
|
||||||
} |
} |
||||||
|
|
||||||
if (mapped_file != MAP_FAILED) { |
void finish (const font_options_t *font_opts) |
||||||
hb_blob_t *font_blob = hb_blob_create(static_cast<const char*>(mapped_file), |
{ |
||||||
stat.st_size, |
hb_face_t *face = hb_font_get_face (font); |
||||||
HB_MEMORY_MODE_READONLY, nullptr, |
hb_blob_t *result = hb_face_reference_blob (face); |
||||||
nullptr); |
unsigned int data_length; |
||||||
|
const char* data = hb_blob_get_data (result, &data_length); |
||||||
|
|
||||||
fd_out = open(argv[2], O_CREAT | O_WRONLY, S_IRWXU); |
int fd_out = open(options.output_file, O_CREAT | O_WRONLY, S_IRWXU); |
||||||
if (fd_out != -1) { |
if (fd_out != -1) { |
||||||
ssize_t bytes_written = write(fd_out, mapped_file, stat.st_size); |
ssize_t bytes_written = write(fd_out, data, data_length); |
||||||
if (bytes_written == -1) { |
if (bytes_written == -1) { |
||||||
perror("Unable to write output file"); |
fprintf(stderr, "Unable to write output file"); |
||||||
exit_code = 1; |
failed = true; |
||||||
} else if (bytes_written != stat.st_size) { |
} else if (bytes_written != data_length) { |
||||||
fprintf(stderr, "Wrong number of bytes written"); |
fprintf(stderr, "Wrong number of bytes written"); |
||||||
exit_code = 1; |
failed = true; |
||||||
} |
} |
||||||
} else { |
} else { |
||||||
perror("Unable to open output file"); |
fprintf(stderr, "Unable to open output file"); |
||||||
exit_code = 1; |
failed = true; |
||||||
} |
} |
||||||
} |
|
||||||
|
|
||||||
if (mapped_file != MAP_FAILED) { |
hb_blob_destroy (result); |
||||||
if (munmap(mapped_file, stat.st_size) == -1) { |
hb_font_destroy (font); |
||||||
perror("Unable to unmap file"); |
|
||||||
exit_code = 1; |
|
||||||
} |
|
||||||
} |
} |
||||||
|
|
||||||
if (fd_out != -1 && close(fd_out) == -1) { |
public: |
||||||
perror("Unable to close output file"); |
bool failed; |
||||||
exit_code = 1; |
|
||||||
} |
|
||||||
|
|
||||||
if (fd != -1 && close(fd) == -1) { |
private: |
||||||
perror("Unable to close file"); |
output_options_t options; |
||||||
exit_code = 1; |
hb_font_t *font; |
||||||
} |
}; |
||||||
|
|
||||||
return exit_code; |
int |
||||||
|
main (int argc, char **argv) |
||||||
|
{ |
||||||
|
main_font_text_t<subset_consumer_t, 10, 0> driver; |
||||||
|
return driver.main (argc, argv); |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue