Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 11 additions & 22 deletions kiva/agg/src/kiva_graphics_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@
#include <string.h>
#include <stack>

#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
#include <windows.h>
#endif

#include <iostream>
#include <memory>
#include <locale>

#include "utf8.h"

#include "agg_trans_affine.h"
#include "agg_path_storage.h"
Expand Down Expand Up @@ -57,6 +54,7 @@
#include "kiva_alpha_gamma.h"
#include "kiva_gradient.h"


namespace kiva
{

Expand Down Expand Up @@ -1292,21 +1290,13 @@ namespace kiva
ScanlineRendererType scanlineRenderer(this->renderer);

const agg24::glyph_cache *glyph = NULL;
#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
int required = MultiByteToWideChar(CP_UTF8, 0, text, -1, 0, 0);
std::vector<wchar_t> p_(required + 1);
MultiByteToWideChar(CP_UTF8, 0, text, -1, &p_[0], required);
wchar_t *p = &p_[0];
#else
std::vector <wchar_t> p_(1024);
size_t length = mbstowcs(&p_[0], text, 1024);
if (length > 1024)
{
p_.resize (length + 1);
mbstowcs(&p_[0], text, length);
}
wchar_t *p = &p_[0];
#endif

// Explicitly decode UTF8 bytes to 32-bit codepoints to feed into the
// font API.
size_t text_length = strlen(text);
utf8::iterator<char*> p(text, text, text+text_length);
utf8::iterator<char*> p_end(text+text_length, text, text+text_length);

bool retval = true;

// Check to make sure the font's loaded.
Expand Down Expand Up @@ -1353,7 +1343,7 @@ namespace kiva
double advance_x = 0.0;
double advance_y = 0.0;

while (*p)
for (; p!=p_end; ++p)
{
double x = start_x + advance_x;
double y = start_y + advance_y;
Expand All @@ -1375,7 +1365,6 @@ namespace kiva

advance_x += glyph->advance_x;
advance_y += glyph->advance_y;
p++;
}

agg24::trans_affine null_xform = agg24::trans_affine_translation(0., 0.);
Expand Down
27 changes: 9 additions & 18 deletions kiva/agg/src/kiva_graphics_context_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#endif

#include <assert.h>

#include "utf8.h"

#include "agg_path_storage.h"
#include "kiva_exceptions.h"
#include "kiva_graphics_context_base.h"
Expand Down Expand Up @@ -580,21 +583,11 @@ kiva::rect_type graphics_context_base::get_text_extent(char *text)
{
const agg24::glyph_cache *glyph = NULL;

#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
int required = MultiByteToWideChar(CP_UTF8, 0, text, -1, 0, 0);
std::vector<wchar_t> p_(required + 1);
MultiByteToWideChar(CP_UTF8, 0, text, -1, &p_[0], required);
wchar_t *p = &p_[0];
#else
std::vector <wchar_t> p_(1024);
size_t length = mbstowcs(&p_[0], text, 1024);
if (length > 1024)
{
p_.resize (length + 1);
mbstowcs(&p_[0], text, length);
}
wchar_t *p = &p_[0];
#endif
// Explicitly decode UTF8 bytes to 32-bit codepoints to feed into the
// font API.
size_t text_length = strlen(text);
utf8::iterator<char*> p(text, text, text+text_length);
utf8::iterator<char*> p_end(text+text_length, text, text+text_length);

double x1 = 0.0, x2 = 0.0, y1 = 0.0, y2= 0.0;

Expand All @@ -608,20 +601,18 @@ kiva::rect_type graphics_context_base::get_text_extent(char *text)
//typedef agg24::glyph_raster_bin<agg24::rgba8> GlyphGeneratorType;
//GlyphGeneratorType glyphGen(this->font_manager.glyph(*p)->data);

while (*p)
for (; p!=p_end; ++p)
{
glyph = font_manager->glyph(*p);
if (glyph == NULL)
{
p++;
continue;
}
font_manager->add_kerning(&x2, &y2);
x1 = kiva::min(x1, glyph->bounds.x1);
x2 += glyph->advance_x;
y1 = kiva::min(y1, glyph->bounds.y1);
y2 = kiva::max(y2, glyph->bounds.y2);
p++;
}

this->_release_font_manager();
Expand Down
34 changes: 34 additions & 0 deletions kiva/agg/src/utf8.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2006 Nemanja Trifunovic

/*
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/


#ifndef UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731
#define UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731

#include "utf8/checked.h"
#include "utf8/unchecked.h"

#endif // header guard
Loading