Click here to Skip to main content
15,885,278 members
Articles / Multimedia / GDI+

How to Use a Font Without Installing it

Rate me:
Please Sign up or sign in to vote.
4.93/5 (58 votes)
12 Apr 2016CPOL7 min read 200.6K   7.5K   185  
How to use a font without installing it first on user systems
/*
Font Name Library 1.0.0

Copyright (c) 2009 Wong Shao Voon

The Code Project Open License (CPOL)
http://www.codeproject.com/info/cpol10.aspx
*/

#include "StdAfx.h"
#include "MemPtrReader.h"
#include <cstdio>

MemPtrReader::MemPtrReader(BYTE *pOrigin, size_t size, size_t offset)
{
	m_pOrigin = pOrigin;
	m_ptr = pOrigin;
	m_pSteps=0;
	m_size = size;
	m_nOffset = offset;
}

MemPtrReader::~MemPtrReader(void)
{
}

int MemPtrReader::Seek( long offset, int origin )
{
	if(origin==SEEK_SET)
	{
		m_ptr = m_pOrigin-m_nOffset;
		m_ptr = m_ptr + offset;
		return 0;
	}
	else if(origin==SEEK_END)
	{
		m_ptr = m_pOrigin-m_nOffset+m_size;
		m_ptr = m_ptr + offset;
		return 0;
	}
	else if(origin==SEEK_CUR)
	{
		m_ptr = m_ptr + offset;
		return 0;
	}

	return 1;
}

size_t MemPtrReader::Read( void *buffer, size_t size, size_t count )
{
	BYTE* buffer2 = (BYTE*)(buffer);
	for(size_t i=0; i<count; ++i)
	{
		memcpy(buffer2,m_ptr,size);
		buffer2 = buffer2 + size;
		m_ptr = m_ptr + size;
	}

	return size * count;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Singapore Singapore
Shao Voon is from Singapore. His interest lies primarily in computer graphics, software optimization, concurrency, security, and Agile methodologies.

In recent years, he shifted focus to software safety research. His hobby is writing a free C++ DirectX photo slideshow application which can be viewed here.

Comments and Discussions