8000 Backport PR #9289 on branch v2.1.x by lumberbot-app[bot] · Pull Request #9297 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Backport PR #9289 on branch v2.1.x #9297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 6, 2017
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
2 changes: 1 addition & 1 deletion lib/matplotlib/tri/_tri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@ TrapezoidMapTriFinder::initialize()
unsigned int nedges = _edges.size();
for (unsigned int index = 2; index < nedges; ++index) {
if (!add_edge_to_tree(_edges[index]))
throw "Triangulation is invalid";
throw std::runtime_error("Triangulation is invalid");
_tree->assert_valid(index == nedges-1);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/_backend_agg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ BufferRegion *RendererAgg::copy_from_bbox(agg::rect_d in_rect)
void RendererAgg::restore_region(BufferRegion &region)
{
if (region.get_data() == NULL) {
throw "Cannot restore_region from NULL data";
throw std::runtime_error("Cannot restore_region from NULL data");
}

agg::rendering_buffer rbuf;
Expand All @@ -115,7 +115,7 @@ void
RendererAgg::restore_region(BufferRegion &region, int xx1, int yy1, int xx2, int yy2, int x, int y )
{
if (region.get_data() == NULL) {
throw "Cannot restore_region from NULL data";
throw std::runtime_error("Cannot restore_region from NULL data");
}

agg::rect_i &rrect = region.get_rect();
Expand Down
12 changes: 6 additions & 6 deletions src/_contour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ void QuadContourGenerator::append_contour_line_to_vertices(
}
if (PyList_Append(vertices_list, line.pyobj_steal())) {
Py_XDECREF(vertices_list);
throw "Unable to add contour line to vertices_list";
throw std::runtime_error("Unable to add contour line to vertices_list");
}

contour_line.clear();
Expand Down Expand Up @@ -475,7 +475,7 @@ void QuadContourGenerator::append_contour_to_vertices_and_codes(
Py_XDECREF(vertices_list);
Py_XDECREF(codes_list);
contour.delete_contour_lines();
throw "Unable to add contour line to vertices and codes lists";
throw std::runtime_error("Unable to add contour line to vertices and codes lists");
}

delete *line_it;
Expand Down Expand Up @@ -510,7 +510,7 @@ PyObject* QuadContourGenerator::create_contour(const double& level)

PyObject* vertices_list = PyList_New(0);
if (vertices_list == 0)
throw "Failed to create Python list";
throw std::runtime_error("Failed to create Python list");

// Lines that start and end on boundaries.
long ichunk, jchunk, istart, iend, jstart, jend;
Expand Down Expand Up @@ -602,12 +602,12 @@ PyObject* QuadContourGenerator::create_filled_contour(const double& lower_level,

PyObject* vertices = PyList_New(0);
if (vertices == 0)
throw "Failed to create Python list";
throw std::runtime_error("Failed to create Python list");

PyObject* codes = PyList_New(0);
if (codes == 0) {
Py_XDECREF(vertices);
throw "Failed to create Python list";
throw std::runtime_error("Failed to create Python list");
}

long ichunk, jchunk, istart, iend, jstart, jend;
Expand Down Expand Up @@ -644,7 +644,7 @@ PyObject* QuadContourGenerator::create_filled_contour(const double& lower_level,
if (tuple == 0) {
Py_XDECREF(vertices);
Py_XDECREF(codes);
throw "Failed to create Python tuple";
throw std::runtime_error("Failed to create Python tuple");
}

// No error checking here as filling in a brand new pre-allocated tuple.
Expand Down
16 changes: 8 additions & 8 deletions src/_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void pcolor(CoordinateArray &x,
OutputArray &out)
{
if (rows >= 32768 || cols >= 32768) {
throw "rows and cols must both be less than 32768";
throw std::runtime_error("rows and cols must both be less than 32768");
}

float x_min = bounds[0];
Expand All @@ -49,18 +49,18 @@ void pcolor(CoordinateArray &x,

// Check we have something to output to
if (rows == 0 || cols == 0) {
throw "Cannot scale to zero size";
throw std::runtime_error("Cannot scale to zero size");
}

if (d.dim(2) != 4) {
throw "data must be in RGBA format";
throw std::runtime_error("data must be in RGBA format");
}

// Check dimensions match
unsigned long nx = x.dim(0);
unsigned long ny = y.dim(0);
if (nx != (unsigned long)d.dim(1) || ny != (unsigned long)d.dim(0)) {
throw "data and axis dimensions do not match";
throw std::runtime_error("data and axis dimensions do not match");
}

// Allocate memory for pointer arrays
Expand Down Expand Up @@ -150,22 +150,22 @@ void pcolor2(CoordinateArray &x,

// Check we have something to output to
if (rows == 0 || cols == 0) {
throw "rows or cols is zero; there are no pixels";
throw std::runtime_error("rows or cols is zero; there are no pixels");
}

if (d.dim(2) != 4) {
throw "data must be in RGBA format";
throw std::runtime_error("data must be in RGBA format");
}

// Check dimensions match
unsigned long nx = x.dim(0);
unsigned long ny = y.dim(0);
if (nx != (unsigned long)d.dim(1) + 1 || ny != (unsigned long)d.dim(0) + 1) {
throw "data and axis bin boundary dimensions are incompatible";
throw std::runtime_error("data and axis bin boundary dimensions are incompatible");
}

if (bg.dim(0) != 4) {
throw "bg must be in RGBA format";
throw std::runtime_error("bg must be in RGBA format");
}

std::vector<int> irows(rows);
Expand Down
6 changes: 3 additions & 3 deletions src/_path.h
28BE
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ void get_path_collection_extents(agg::trans_affine &master_transform,
extent_limits &extent)
{
if (offsets.size() != 0 && offsets.dim(1) != 2) {
throw "Offsets array must be Nx2";
throw std::runtime_error("Offsets array must be Nx2");
}

size_t Npaths = paths.size();
Expand Down Expand Up @@ -728,7 +728,7 @@ template <class VerticesArray, class ResultArray>
void affine_transform_2d(VerticesArray &vertices, agg::trans_affine &trans, ResultArray &result)
{
if (vertices.size() != 0 && vertices.dim(1) != 2) {
throw "Invalid vertices array.";
throw std::runtime_error("Invalid vertices array.");
}

size_t n = vertices.size();
Expand Down Expand Up @@ -758,7 +758,7 @@ template <class VerticesArray, class ResultArray>
void affine_transform_1d(VerticesArray &vertices, agg::trans_affine &trans, ResultArray &result)
{
if (vertices.dim(0) != 2) {
throw "Invalid vertices array.";
throw std::runtime_error("Invalid vertices array.");
}

double x;
Expand Down
4 changes: 2 additions & 2 deletions src/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ class empty

T &operator()(int i, int j = 0, int k = 0)
{
throw "Accessed empty array";
throw std::runtime_error("Accessed empty array");
}

const T &operator()(int i, int j = 0, int k = 0) const
{
throw "Accessed empty array";
throw std::runtime_error("Accessed empty array");
}

sub_t operator[](int i) const
Expand Down
55 changes: 28 additions & 27 deletions src/ft2font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

#define NO_IMPORT_ARRAY

#include <string>
#include <algorithm>
#include <stdexcept>
#include <string>

#include "ft2font.h"
#include "mplutils.h"
Expand Down Expand Up @@ -115,7 +116,7 @@ void FT2Image::draw_bitmap(FT_Bitmap *bitmap, FT_Int x, FT_Int y)
}
}
} else {
throw "Unknown pixel mode";
throw std::runtime_error("Unknown pixel mode");
}

m_dirty = true;
Expand All @@ -124,7 +125,7 @@ void FT2Image::draw_bitmap(FT_Bitmap *bitmap, FT_Int x, FT_Int y)
void FT2Image::draw_rect(unsigned long x0, unsigned long y0, unsigned long x1, unsigned long y1)
{
if (x0 > m_width || x1 > m_width || y0 > m_height || y1 > m_height) {
throw "Rect coords outside image bounds";
throw std::runtime_error("Rect coords outside image bounds");
}

size_t top = y0 * m_width;
Expand Down Expand Up @@ -170,7 +171,7 @@ int FT2Font::get_path_count()
// this code is from agg's decompose_ft_outline with minor modifications

if (!face->glyph) {
throw "No glyph loaded";
throw std::runtime_error("No glyph loaded");
}

FT_Outline &outline = face->glyph->outline;
Expand Down Expand Up @@ -208,7 +209,7 @@ int FT2Font::get_path_count()

// A contour cannot start with a cubic control point!
if (tag == FT_CURVE_TAG_CUBIC) {
throw "A contour cannot start with a cubic control point";
throw std::runtime_error("A contour cannot start with a cubic control point");
} else if (tag == FT_CURVE_TAG_CONIC) {
starts_with_last = true;
} else {
Expand Down Expand Up @@ -246,7 +247,7 @@ int FT2Font::get_path_count()
}

if (tag != FT_CURVE_TAG_CONIC) {
throw "Invalid font";
throw std::runtime_error("Invalid font");
}

count += 2;
Expand All @@ -262,7 +263,7 @@ int FT2Font::get_path_count()
default: // FT_CURVE_TAG_CUBIC
{
if (point + 1 > limit || FT_CURVE_TAG(tags[1]) != FT_CURVE_TAG_CUBIC) {
throw "Invalid font";
throw std::runtime_error("Invalid font");
}

point += 2;
Expand Down Expand Up @@ -492,13 +493,13 @@ FT2Font::FT2Font(FT_Open_Args &open_args, long hinting_factor_) : image(), face(
int error = FT_Open_Face(_ft2Library, &open_args, 0, &face);

if (error == FT_Err_Unknown_File_Format) {
throw "Can not load face. Unknown file format.";
throw std::runtime_error("Can not load face. Unknown file format.");
} else if (error == FT_Err_Cannot_Open_Resource) {
throw "Can not load face. Can not open resource.";
throw std::runtime_error("Can not load face. Can not open resource.");
} else if (error == FT_Err_Invalid_File_Format) {
throw "Can not load face. Invalid file format.";
throw std::runtime_error("Can not load face. Invalid file format.");
} else if (error) {
throw "Can not load face.";
throw std::runtime_error("Can not load face.");
}

// set a default fontsize 12 pt at 72dpi
Expand All @@ -507,7 +508,7 @@ FT2Font::FT2Font(FT_Open_Args &open_args, long hinting_factor_) : image(), face(
error = FT_Set_Char_Size(face, 12 * 64, 0, 72 * (unsigned int)hinting_factor, 72);
if (error) {
FT_Done_Face(face);
throw "Could not set the fontsize";
throw std::runtime_error("Could not set the fontsize");
}

if (open_args.stream != NULL) {
Expand Down Expand Up @@ -551,25 +552,25 @@ void FT2Font::set_size(double ptsize, double dpi)
FT_Set_Transform(face, &transform, 0);

if (error) {
throw "Could not set the fontsize";
throw std::runtime_error("Could not set the fontsize");
}
}

void FT2Font::set_charmap(int i)
{
if (i >= face->num_charmaps) {
throw "i exceeds the available number of char maps";
throw std::runtime_error("i exceeds the available number of char maps");
}
FT_CharMap charmap = face->charmaps[i];
if (FT_Set_Charmap(face, charmap)) {
throw "Could not set the charmap";
throw std::runtime_error("Could not set the charmap");
}
}

void FT2Font::select_charmap(unsigned long i)
{
if (FT_Select_Charmap(face, (FT_Encoding)i)) {
throw "Could not set the charmap";
throw std::runtime_error("Could not set the charmap");
}
}

Expand Down Expand Up @@ -622,7 +623,7 @@ void FT2Font::set_text(
}
error = FT_Load_Glyph(face, glyph_index, flags);
if (error) {
throw "could not load glyph";
throw std::runtime_error("could not load glyph");
}
// ignore errors, jump to next glyph

Expand All @@ -632,7 +633,7 @@ void FT2Font::set_text(
error = FT_Get_Glyph(face->glyph, &thisGlyph);

if (error) {
throw "could not get glyph";
throw std::runtime_error("could not get glyph");
}
// ignore errors, jump to next glyph

Expand Down Expand Up @@ -668,14 +669,14 @@ void FT2Font::load_char(long charcode, FT_Int32 flags)
int error = FT_Load_Char(face, (unsigned long)charcode, flags);

if (error) {
throw "Could not load charcode";
throw std::runtime_error("Could not load charcode");
}

FT_Glyph thisGlyph;
error = FT_Get_Glyph(face->glyph, &thisGlyph);

if (error) {
throw "Could not get glyph";
throw std::runtime_error("Could not get glyph");
}

glyphs.push_back(thisGlyph);
Expand All @@ -686,14 +687,14 @@ void FT2Font::load_glyph(FT_UInt glyph_index, FT_Int32 flags)
int error = FT_Load_Glyph(face, glyph_index, flags);

if (error) {
throw "Could not load glyph";
throw std::runtime_error("Could not load glyph");
}

FT_Glyph thisGlyph;
error = FT_Get_Glyph(face->glyph, &thisGlyph);

if (error) {
throw "Could not load glyph";
throw std::runtime_error("Could not load glyph");
}

glyphs.push_back(thisGlyph);
Expand Down Expand Up @@ -727,7 +728,7 @@ void FT2Font::draw_glyphs_to_bitmap(bool antialiased)
error = FT_Glyph_To_Bitmap(
&glyphs[n], antialiased ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO, 0, 1);
if (error) {
throw "Could not convert glyph to bitmap";
throw std::runtime_error("Could not convert glyph to bitmap");
}

FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyphs[n];
Expand All @@ -748,7 +749,7 @@ void FT2Font::get_xys(bool antialiased, std::vector<double> &xys)
error = FT_Glyph_To_Bitmap(
&glyphs[n], antialiased ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO, 0, 1);
if (error) {
throw "Could not convert glyph to bitmap";
throw std::runtime_error("Could not convert glyph to bitmap");
}

FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyphs[n];
Expand All @@ -771,7 +772,7 @@ void FT2Font::draw_glyph_to_bitmap(FT2Image &im, int x, int y, size_t glyphInd,
sub_offset.y = 0; // int((yd - (double)y) * 64.0);

if (glyphInd >= glyphs.size()) {
throw "glyph num is out of range";
throw std::runtime_error("glyph num is out of range");
}

error = FT_Glyph_To_Bitmap(&glyphs[glyphInd],
Expand All @@ -780,7 +781,7 @@ void FT2Font::draw_glyph_to_bitmap(FT2Image &im, int x, int y, size_t glyphInd,
1 // destroy image
);
if (error) {
throw "Could not convert glyph to bitmap";
throw std::runtime_error("Could not convert glyph to bitmap");
}

FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyphs[glyphInd];
Expand All @@ -796,7 +797,7 @@ void FT2Font::get_glyph_name(unsigned int glyph_number, char *buffer)
PyOS_snprintf(buffer, 128, "uni%08x", glyph_number);
} else {
if (FT_Get_Glyph_Name(face, glyph_number, buffer, 128)) {
throw "Could not get glyph names.";
throw std::runtime_error("Could not get glyph names.");
}
}
}
Expand Down
Loading
0