11512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod/* 21512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * Copyright (C) 2005 David Turner 31512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 41512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * Copyright (C) 2007 Red Hat, Inc. 51512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * 61512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * This is part of HarfBuzz, an OpenType Layout engine library. 71512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * 81512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * Permission is hereby granted, without written agreement and without 91512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * license or royalty fees, to use, copy, modify, and distribute this 101512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * software and its documentation for any purpose, provided that the 111512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * above copyright notice and the following two paragraphs appear in 121512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * all copies of this software. 131512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * 141512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 151512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 161512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 171512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 181512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * DAMAGE. 191512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * 201512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 211512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 221512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 231512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 241512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 251512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * 261512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod * Red Hat Author(s): Behdad Esfahbod 271512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod */ 281512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod 291512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod#include "harfbuzz-impl.h" 301512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod#include "harfbuzz-stream-private.h" 311512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod#include <stdlib.h> 321512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod 331512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod#if 0 341512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod#include <stdio.h> 351512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod#define LOG(x) _hb_log x 361512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod 371512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbodstatic void 381512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod_hb_log( const char* format, ... ) 391512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod{ 401512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod va_list ap; 411512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod 421512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod va_start( ap, format ); 431512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod vfprintf( stderr, format, ap ); 441512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod va_end( ap ); 451512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod} 461512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod 471512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod#else 481512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod#define LOG(x) do {} while (0) 491512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod#endif 501512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod 511512a7357513b72e2a07dda706a176bb23d694e9Behdad EsfahbodHB_INTERNAL void 521512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod_hb_close_stream( HB_Stream stream ) 531512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod{ 541512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod if (!stream) 551512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod return; 561512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod free(stream->base); 571512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod free(stream); 581512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod} 591512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod 601512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod 611512a7357513b72e2a07dda706a176bb23d694e9Behdad EsfahbodHB_INTERNAL HB_Int 621512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod_hb_stream_pos( HB_Stream stream ) 631512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod{ 641512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod LOG(( "_hb_stream_pos() -> %ld\n", stream->pos )); 651512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod return stream->pos; 661512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod} 671512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod 681512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod 691512a7357513b72e2a07dda706a176bb23d694e9Behdad EsfahbodHB_INTERNAL HB_Error 701512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod_hb_stream_seek( HB_Stream stream, 711512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod HB_UInt pos ) 721512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod{ 731512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod HB_Error error = (HB_Error)0; 741512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod 751512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod stream->pos = pos; 761512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod if (pos > stream->size) 771512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod error = ERR(HB_Err_Read_Error); 781512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod 791512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod LOG(( "_hb_stream_seek(%ld) -> 0x%04X\n", pos, error )); 801512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod return error; 811512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod} 821512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod 831512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod 841512a7357513b72e2a07dda706a176bb23d694e9Behdad EsfahbodHB_INTERNAL HB_Error 851512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod_hb_stream_frame_enter( HB_Stream stream, 861512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod HB_UInt count ) 871512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod{ 881512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod HB_Error error = HB_Err_Ok; 891512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod 901512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod /* check new position, watch for overflow */ 911512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod if (HB_UNLIKELY (stream->pos + count > stream->size || 921512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod stream->pos + count < stream->pos)) 931512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod { 941512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod error = ERR(HB_Err_Read_Error); 951512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod goto Exit; 961512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod } 971512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod 981512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod /* set cursor */ 991512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod stream->cursor = stream->base + stream->pos; 1001512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod stream->pos += count; 1011512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod 1021512a7357513b72e2a07dda706a176bb23d694e9Behdad EsfahbodExit: 1031512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod LOG(( "_hb_stream_frame_enter(%ld) -> 0x%04X\n", count, error )); 1041512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod return error; 1051512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod} 1061512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod 1071512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod 1081512a7357513b72e2a07dda706a176bb23d694e9Behdad EsfahbodHB_INTERNAL void 1091512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod_hb_stream_frame_exit( HB_Stream stream ) 1101512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod{ 1111512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod stream->cursor = NULL; 1121512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod 1131512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod LOG(( "_hb_stream_frame_exit()\n" )); 1141512a7357513b72e2a07dda706a176bb23d694e9Behdad Esfahbod} 115