コード例 #1
0
ファイル: iimport.cpp プロジェクト: soapdog/livecode
bool MCImageGetMetafileGeometry(IO_handle p_stream, uindex_t &r_width, uindex_t &r_height)
{
	bool t_success = true;
	bool t_is_meta = false;

	uindex_t t_stream_pos = MCS_tell(p_stream);
	uint8_t t_head[DRAWING_HEAD_SIZE];
	uindex_t t_size = DRAWING_HEAD_SIZE;

	t_success = IO_NORMAL == MCS_readfixed(t_head, t_size, p_stream) &&
		t_size == DRAWING_HEAD_SIZE;
    
   /* A drawing's header is of the form:
     *   0: LCD\0
     *   4: width
     *   8: height
     */
	if (t_success &&
        memcmp(t_head, "LCD\0", 4) == 0)
	{
        float t_width = *(const float *)(t_head + 4);
        float t_height = *(const float *)(t_head + 8);
        
        /* The engine deals with integer bounds on sub-pixel co-ords, so
         * take the ceiling of the computer (float) width/height. */
        r_width = (uindex_t)ceilf(t_width);
        r_height = (uindex_t)ceilf(t_height);
        
        t_is_meta = true;
    }
    
	MCS_seek_set(p_stream, t_stream_pos);
    
    return t_success && t_is_meta;
}
コード例 #2
0
ファイル: srvcgi.cpp プロジェクト: bduck/livecode
bool MCStreamCache::ReadFromCache(void *p_buffer, uint32_t p_offset, uint32_t p_length, uint32_t &r_read)
{
	uint32_t t_to_read;
	if (m_cache_buffer != NULL)
	{
		r_read = MCMin(p_length, m_cache_length - p_offset);
		MCMemoryCopy(p_buffer, (uint8_t*)m_cache_buffer + p_offset, r_read);
		return true;
	}
	else if (m_cache_file != NULL)
	{
		bool t_success = true;
		
		IO_stat t_status;
		
		t_success = (IO_NORMAL == MCS_seek_set(m_cache_file, p_offset));
		if (t_success)
			t_success = (IO_ERROR != MCS_read(p_buffer, 1, p_length, m_cache_file));
		
		if (t_success)
		{
			r_read = p_length;
		}
		
		return t_success;
	}
	
	r_read = 0;
	return true;
}
コード例 #3
0
		bool Rewind(void)
		{
			return MCS_seek_set(handle, 0) == IO_NORMAL;
		}
コード例 #4
0
ファイル: dispatch.cpp プロジェクト: runrevelanor/livecode
// MW-2012-02-17: [[ LogFonts ]] Actually load the stack file (wrapped by readfile
//   to handle font table cleanup).
IO_stat MCDispatch::doreadfile(const char *openpath, const char *inname, IO_handle &stream, MCStack *&sptr)
{
	Boolean loadhome = False;
	char version[8];

	if (readheader(stream, version) == IO_NORMAL)
	{
		if (strcmp(version, MCversionstring) > 0)
		{
			MCresult->sets("stack was produced by a newer version");
			return IO_ERROR;
		}

		// MW-2008-10-20: [[ ParentScripts ]] Set the boolean flag that tells us whether
		//   parentscript resolution is required to false.
		s_loaded_parent_script_reference = false;

		uint1 charset, type;
		char *newsf;
		if (IO_read_uint1(&charset, stream) != IO_NORMAL
		        || IO_read_uint1(&type, stream) != IO_NORMAL
		        || IO_read_string(newsf, stream) != IO_NORMAL)
		{
			MCresult->sets("stack is corrupted, check for ~ backup file");
			return IO_ERROR;
		}
		delete newsf; // stackfiles is obsolete
		MCtranslatechars = charset != CHARSET;
		sptr = nil;
		/* UNCHECKED */ MCStackSecurityCreateStack(sptr);
		if (stacks == NULL)
			sptr->setparent(this);
		else
			sptr->setparent(stacks);
		sptr->setfilename(strclone(openpath));

		if (MCModeCanLoadHome() && type == OT_HOME)
		{
			char *lstring = NULL;
			char *cstring = NULL;
			IO_read_string(lstring, stream);
			IO_read_string(cstring, stream);
			delete lstring;
			delete cstring;
		}

		MCresult -> clear();

		if (IO_read_uint1(&type, stream) != IO_NORMAL
		    || type != OT_STACK && type != OT_ENCRYPT_STACK
		    || sptr->load(stream, version, type) != IO_NORMAL)
		{
			if (MCresult -> isclear())
				MCresult->sets("stack is corrupted, check for ~ backup file");
			destroystack(sptr, False);
			sptr = NULL;
			return IO_ERROR;
		}
		
		// MW-2011-08-09: [[ Groups ]] Make sure F_GROUP_SHARED is set
		//   appropriately.
		sptr -> checksharedgroups();
		
		if (sptr->load_substacks(stream, version) != IO_NORMAL
		        || IO_read_uint1(&type, stream) != IO_NORMAL
		        || type != OT_END)
		{
			if (MCresult -> isclear())
				MCresult->sets("stack is corrupted, check for ~ backup file");
			destroystack(sptr, False);
			sptr = NULL;
			return IO_ERROR;
		}

		if (stacks != NULL)
		{
			MCStack *tstk = stacks;
			do
			{
				if (sptr->hasname(tstk->getname()))
				{
					MCAutoNameRef t_stack_name;
					/* UNCHECKED */ t_stack_name . Clone(sptr -> getname());

					delete sptr;
					sptr = NULL;

					if (strequal(tstk->getfilename(), openpath))
						sptr = tstk;
					else
					{
						MCdefaultstackptr->getcard()->message_with_args(MCM_reload_stack, MCNameGetOldString(tstk->getname()), openpath);
						tstk = stacks;
						do
						{
							if (MCNameIsEqualTo(t_stack_name, tstk->getname(), kMCCompareCaseless))
							{
								sptr = tstk;
								break;
							}
							tstk = (MCStack *)tstk->next();
						}
						while (tstk != stacks);
					}

					return IO_NORMAL;
				}
				tstk = (MCStack *)tstk->next();
			}
			while (tstk != stacks);
		}
		
		appendstack(sptr);
		
		sptr->extraopen(false);

		// MW-2008-10-28: [[ ParentScript ]]
		// We just loaded a stackfile, so check to see if parentScript resolution
		// is required and if so do it.
		// MW-2009-01-28: [[ Inherited parentScripts ]]
		// Resolving parentScripts may allocate memory, so 'resolveparentscripts'
		// will return false if it fails to allocate what it needs. At some point
		// this needs to be dealt with by deleting the stack and returning an error,
		// *However* at the time of writing, 'readfile' isn't designed to handle
		// this - so we just ignore the result for now (note that all the 'load'
		// methods *fail* to check for no-memory errors!).
		if (s_loaded_parent_script_reference)
			sptr -> resolveparentscripts();
		
	}
	else
	{
		MCS_seek_set(stream, 0);
		if (stacks == NULL)
		{
			MCnoui = True;
			MCscreen = new MCUIDC;
			/* UNCHECKED */ MCStackSecurityCreateStack(stacks);
			MCdefaultstackptr = MCstaticdefaultstackptr = stacks;
			stacks->setparent(this);
			stacks->setname_cstring("revScript");
			uint4 size = (uint4)MCS_fsize(stream);
			char *script = new char[size + 2];
			script[size] = '\n';
			script[size + 1] = '\0';
			if (IO_read(script, sizeof(char), size, stream) != IO_NORMAL
			        || !stacks->setscript(script))
			{
				delete script;
				return IO_ERROR;
			}
		}
		else
		{
			char *tname = strclone(inname);
			
			// MW-2008-06-12: [[ Bug 6476 ]] Media won't open HC stacks
			if (!MCdispatcher->cut(True) || hc_import(tname, stream, sptr) != IO_NORMAL)
			{
				MCresult->sets("file is not a stack");
				delete tname;
				return IO_ERROR;
			}
		}
	}
	return IO_NORMAL;
}
コード例 #5
0
ファイル: iimport.cpp プロジェクト: Bjoernke/livecode
bool MCImageGetMetafileGeometry(IO_handle p_stream, uindex_t &r_width, uindex_t &r_height)
{
	bool t_success = true;
	bool t_is_meta = false;

	uindex_t t_stream_pos = MCS_tell(p_stream);
	uint8_t t_head[EMF_HEAD_SIZE];
	uindex_t t_size = META_HEAD_SIZE;

	t_success = IO_NORMAL == MCS_read(t_head, sizeof(uint8_t), t_size, p_stream) &&
		t_size == META_HEAD_SIZE;

	if (t_success)
	{
		// graphics metafile (wmf)
		if (memcmp(t_head, "\xD7\xCD\xC6\x9A", 4) == 0)
		{
			int16_t *t_bounds = (int16_t *)&t_head[6];
			r_width = ((t_bounds[2] - t_bounds[0]) * 72 + t_bounds[4] - 1) / t_bounds[4];
			r_height = ((t_bounds[3] - t_bounds[1]) * 72 + t_bounds[4] - 1) / t_bounds[4];
			t_is_meta = true;
		}
		// win32 metafile (emf)
		else if (memcmp(&t_head[40], "\x20\x45\x4D\x46", 4) == 0)
		{
			t_size = EMF_HEAD_SIZE;
			t_success = IO_NORMAL == MCS_seek_set(p_stream, t_stream_pos) &&
				IO_NORMAL == MCS_read(t_head, sizeof(uint8_t), t_size, p_stream) &&
				t_size == EMF_HEAD_SIZE;

			if (t_success)
			{
				int32_t *t_bounds;
				t_bounds = (int32_t*)&t_head[72];
				r_width = t_bounds[0];
				r_height = t_bounds[1];
				t_is_meta = true;
			}
		}
		else
		{
			uindex_t t_offset = 0;
			if (memcmp(t_head, "\0\0\0\0\0\0\0\0", 8) == 0)
			{
				t_size = META_HEAD_SIZE;
				t_offset = 512;
				t_success = IO_NORMAL == MCS_seek_set(p_stream, t_stream_pos + t_offset) &&
					IO_NORMAL == MCS_read(t_head, sizeof(uint8_t), t_size, p_stream) &&
					t_size == META_HEAD_SIZE;
			}

			// PICT file
			if (t_success && memcmp(&t_head[10], "\0\021\002\377", 4) == 0)
			{
				uint16_t *t_bounds = (uint16_t *)t_head;
				r_width = swap_uint2(&t_bounds[4]) - swap_uint2(&t_bounds[2]);
				r_height = swap_uint2(&t_bounds[3]) - swap_uint2(&t_bounds[1]);
				t_is_meta = true;
				t_stream_pos += t_offset;
			}
		}
	}

	MCS_seek_set(p_stream, t_stream_pos);

	return t_success && t_is_meta;
}