Skip to content

Commit

Permalink
update libxlsx to version 0.8.6
Browse files Browse the repository at this point in the history
  • Loading branch information
j2doll committed Apr 19, 2019
1 parent 48bb4f4 commit fa39efd
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 48 deletions.
2 changes: 1 addition & 1 deletion libxlsxwriter/include/xlsxwriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
#include "xlsxwriter/format.h"
#include "xlsxwriter/utility.h"

#define LXW_VERSION "0.8.5"
#define LXW_VERSION "0.8.6"

#endif /* __LXW_XLSXWRITER_H__ */
3 changes: 0 additions & 3 deletions libxlsxwriter/include/xlsxwriter/packager.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ typedef struct lxw_packager {
char *buffer;
char *tmpdir;

uint16_t chart_count;
uint16_t drawing_count;

} lxw_packager;


Expand Down
2 changes: 1 addition & 1 deletion libxlsxwriter/src/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ format_set_rotation(lxw_format *self, int16_t angle)
if (angle == 270) {
self->rotation = 255;
}
else if (angle >= -90 || angle <= 90) {
else if (angle >= -90 && angle <= 90) {
if (angle < 0)
angle = -angle + 90;

Expand Down
102 changes: 67 additions & 35 deletions libxlsxwriter/src/packager.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,29 @@ _write_chart_files(lxw_packager *self)
err = _add_file_to_zip(self, chart->file, sheetname);
RETURN_ON_ERROR(err);

self->chart_count++;

fclose(chart->file);
}

return LXW_NO_ERROR;
}

/*
* Count the chart files.
*/
uint16_t
_get_chart_count(lxw_packager *self)
{
lxw_workbook *workbook = self->workbook;
lxw_chart *chart;
uint16_t chart_count = 0;

STAILQ_FOREACH(chart, workbook->ordered_charts, ordered_list_pointers) {
chart_count++;
}

return chart_count;
}

/*
* Write the drawing files.
*/
Expand Down Expand Up @@ -362,14 +377,39 @@ _write_drawing_files(lxw_packager *self)
RETURN_ON_ERROR(err);

fclose(drawing->file);

self->drawing_count++;
}
}

return LXW_NO_ERROR;
}

/*
* Count the drawing files.
*/
uint16_t
_get_drawing_count(lxw_packager *self)
{
lxw_workbook *workbook = self->workbook;
lxw_sheet *sheet;
lxw_worksheet *worksheet;
lxw_drawing *drawing;
uint16_t drawing_count = 0;

STAILQ_FOREACH(sheet, workbook->sheets, list_pointers) {
if (sheet->is_chartsheet)
worksheet = sheet->u.chartsheet->worksheet;
else
worksheet = sheet->u.worksheet;

drawing = worksheet->drawing;

if (drawing)
drawing_count++;
}

return drawing_count;
}

/*
* Write the sharedStrings.xml file.
*/
Expand Down Expand Up @@ -657,6 +697,8 @@ _write_content_types_file(lxw_packager *self)
uint16_t index = 1;
uint16_t worksheet_index = 1;
uint16_t chartsheet_index = 1;
uint16_t drawing_count = _get_drawing_count(self);
uint16_t chart_count = _get_chart_count(self);
lxw_error err = LXW_NO_ERROR;

if (!content_types) {
Expand Down Expand Up @@ -692,13 +734,13 @@ _write_content_types_file(lxw_packager *self)
}
}

for (index = 1; index <= self->chart_count; index++) {
for (index = 1; index <= chart_count; index++) {
lxw_snprintf(filename, LXW_FILENAME_LENGTH, "/xl/charts/chart%d.xml",
index);
lxw_ct_add_chart_name(content_types, filename);
}

for (index = 1; index <= self->drawing_count; index++) {
for (index = 1; index <= drawing_count; index++) {
lxw_snprintf(filename, LXW_FILENAME_LENGTH,
"/xl/drawings/drawing%d.xml", index);
lxw_ct_add_drawing_name(content_types, filename);
Expand Down Expand Up @@ -1056,16 +1098,11 @@ _add_file_to_zip(lxw_packager *self, FILE * file, const char *filename)
size_read = fread(self->buffer, 1, self->buffer_size, file);
}

if (error < 0) {
error = zipCloseFileInZip(self->zipfile);
if (error != ZIP_OK) {
LXW_ERROR("Error in closing member in the zipfile");
RETURN_ON_ZIP_ERROR(error, LXW_ERROR_ZIP_FILE_ADD);
}
else {
error = zipCloseFileInZip(self->zipfile);
if (error != ZIP_OK) {
LXW_ERROR("Error in closing member in the zipfile");
RETURN_ON_ZIP_ERROR(error, LXW_ERROR_ZIP_FILE_ADD);
}
}

return LXW_NO_ERROR;
}
Expand Down Expand Up @@ -1097,16 +1134,11 @@ _add_buffer_to_zip(lxw_packager *self, unsigned char *buffer,
RETURN_ON_ZIP_ERROR(error, LXW_ERROR_ZIP_FILE_ADD);
}

if (error < 0) {
error = zipCloseFileInZip(self->zipfile);
if (error != ZIP_OK) {
LXW_ERROR("Error in closing member in the zipfile");
RETURN_ON_ZIP_ERROR(error, LXW_ERROR_ZIP_FILE_ADD);
}
else {
error = zipCloseFileInZip(self->zipfile);
if (error != ZIP_OK) {
LXW_ERROR("Error in closing member in the zipfile");
RETURN_ON_ZIP_ERROR(error, LXW_ERROR_ZIP_FILE_ADD);
}
}

return LXW_NO_ERROR;
}
Expand All @@ -1120,6 +1152,15 @@ lxw_create_package(lxw_packager *self)
lxw_error error;
int8_t zip_error;

error = _write_content_types_file(self);
RETURN_ON_ERROR(error);

error = _write_root_rels_file(self);
RETURN_ON_ERROR(error);

error = _write_workbook_rels_file(self);
RETURN_ON_ERROR(error);

error = _write_worksheet_files(self);
RETURN_ON_ERROR(error);

Expand All @@ -1138,12 +1179,6 @@ lxw_create_package(lxw_packager *self)
error = _write_shared_strings_file(self);
RETURN_ON_ERROR(error);

error = _write_app_file(self);
RETURN_ON_ERROR(error);

error = _write_core_file(self);
RETURN_ON_ERROR(error);

error = _write_custom_file(self);
RETURN_ON_ERROR(error);

Expand All @@ -1153,12 +1188,6 @@ lxw_create_package(lxw_packager *self)
error = _write_styles_file(self);
RETURN_ON_ERROR(error);

error = _write_content_types_file(self);
RETURN_ON_ERROR(error);

error = _write_workbook_rels_file(self);
RETURN_ON_ERROR(error);

error = _write_worksheet_rels_file(self);
RETURN_ON_ERROR(error);

Expand All @@ -1171,7 +1200,10 @@ lxw_create_package(lxw_packager *self)
error = _write_image_files(self);
RETURN_ON_ERROR(error);

error = _write_root_rels_file(self);
error = _write_core_file(self);
RETURN_ON_ERROR(error);

error = _write_app_file(self);
RETURN_ON_ERROR(error);

zip_error = zipClose(self->zipfile, NULL);
Expand Down
29 changes: 21 additions & 8 deletions libxlsxwriter/src/worksheet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,9 @@ _worksheet_size_col(lxw_worksheet *self, lxw_col_t col_num)
}

if (col_opt) {
if (col_opt->hidden)
return 0;

width = col_opt->width;

/* Convert to pixels. */
Expand Down Expand Up @@ -1775,6 +1778,9 @@ _worksheet_size_row(lxw_worksheet *self, lxw_row_t row_num)
row = lxw_worksheet_find_row(self, row_num);

if (row) {
if (row->hidden)
return 0;

height = row->height;

if (height == 0)
Expand Down Expand Up @@ -1901,23 +1907,30 @@ _worksheet_position_object_pixels(lxw_worksheet *self,
y_abs += y1;

/* Adjust start col for offsets that are greater than the col width. */
while (x1 >= _worksheet_size_col(self, col_start)) {
x1 -= _worksheet_size_col(self, col_start);
col_start++;
if (_worksheet_size_col(self, col_start) > 0) {
while (x1 >= _worksheet_size_col(self, col_start)) {
x1 -= _worksheet_size_col(self, col_start);
col_start++;
}
}

/* Adjust start row for offsets that are greater than the row height. */
while (y1 >= _worksheet_size_row(self, row_start)) {
y1 -= _worksheet_size_row(self, row_start);
row_start++;
if (_worksheet_size_row(self, row_start) > 0) {
while (y1 >= _worksheet_size_row(self, row_start)) {
y1 -= _worksheet_size_row(self, row_start);
row_start++;
}
}

/* Initialize end cell to the same as the start cell. */
col_end = col_start;
row_end = row_start;

width = width + x1;
height = height + y1;
/* Only offset the image in the cell if the row/col isn't hidden. */
if (_worksheet_size_col(self, col_start) > 0)
width = width + x1;
if (_worksheet_size_row(self, row_start) > 0)
height = height + y1;

/* Subtract the underlying cell widths to find the end cell. */
while (width >= _worksheet_size_col(self, col_end)) {
Expand Down

0 comments on commit fa39efd

Please sign in to comment.