static void set_layout(GnmStyle * style,const psiconv_sheet_cell_layout psi_layout) { GnmColor *color; set_format(style,psi_layout->numberformat); gnm_style_set_font_size(style,psi_layout->character->font_size); gnm_style_set_font_italic(style,psi_layout->character->italic?TRUE:FALSE); gnm_style_set_font_bold(style,psi_layout->character->bold?TRUE:FALSE); gnm_style_set_font_uline(style, psi_layout->character->underline?TRUE:FALSE); gnm_style_set_font_strike(style, psi_layout->character->strikethrough?TRUE:FALSE); gnm_style_set_font_name(style, (const char *) psi_layout->character->font->name); color = get_color(psi_layout->character->color); if (color) gnm_style_set_font_color (style, color); /* TODO: Character level layouts: super_sub */ /* TODO: Paragraph level layouts: all */ /* TODO: Background color: add transparant if white */ #if 0 color = get_color(psi_layout->paragraph->back_color); if (color) { gnm_style_set_back_color(style, color); gnm_style_set_pattern_color(style, color); /* TODO: Replace 24 with some symbol */ gnm_style_set_pattern(style,1); } #endif }
static gboolean sylk_rtd_p_parse (SylkReader *state, char *str) { char *next; int font_size; GnmStyle *font = NULL; for (; *str != '\0' ; str = next) { next = sylk_next_token (str); switch (*str) { case 'P' : /* format */ g_ptr_array_add (state->formats, go_format_new_from_XL (str+1)); break; case 'F' : /* some sort of global font name */ break; case 'E' : /* font name */ if (str[1] != '\0') { if (NULL == font) font = gnm_style_new (); gnm_style_set_font_name (font, str+1); } break; case 'L' : /* font color ? */ break; case 'M' : /* font size * 20 */ if (sylk_parse_int (str+1, &font_size) && font_size > 0) { if (NULL == font) font = gnm_style_new (); gnm_style_set_font_size (font, font_size / 20.0); } break; case 'S' : for (str++ ; *str && *str != ';' ; str++) switch (*str) { case 'I': if (NULL == font) font = gnm_style_new (); gnm_style_set_font_italic (font, TRUE); break; case 'B': if (NULL == font) font = gnm_style_new (); gnm_style_set_font_bold (font, TRUE); break; } break; default : sylk_read_warning (state, "unknown P option '%c'", *str); } } if (NULL != font) g_ptr_array_add (state->fonts, font); return TRUE; }
static void thrash_insert (Sheet *sheet) { int j; GnmStyle *style1 = gnm_style_new (); GnmStyle *style2 = gnm_style_new (); gnm_style_set_font_bold (style1, TRUE); gnm_style_set_font_italic (style1, TRUE); gnm_style_set_font_size (style2, 20.0); for (j = 0; j < INSERT_HEIGHT; j++) { GnmRange r; int i; for (i = 0; i < INSERT_WIDTH; i++) { GnmCell *cell; GnmStyle *setstyle; r.start.col = i; r.start.row = j; r.end = r.start; if (((i / 31) % 2) == 0) setstyle = style1; else setstyle = style2; gnm_style_ref (setstyle); sheet_style_attach (sheet, &r, setstyle); cell = sheet_cell_fetch (sheet, i, j); gnm_cell_set_value (cell, value_new_int (i), NULL); } r.start.col = 0; r.start.row = MAX (0, j - 1); r.end.col = gnm_sheet_get_max_cols (sheet); r.end.row = MIN (gnm_sheet_get_max_rows (sheet), j + 1); sheet_style_optimize (sheet, r); } gnm_style_unref (style1); gnm_style_unref (style2); }
static gboolean sylk_rtd_f_parse (SylkReader *state, char *str) { GnmStyle *style = NULL; char *next; int tmp, size = -1; gboolean is_default_style = FALSE; int full_col = -1, full_row = -1; for (; *str != '\0' ; str = next) { next = sylk_next_token (str); switch (*str) { case 'D': /* Default sheet style ;D<fmt-id><digits><alignment><num_cols??> default Format. */ is_default_style = TRUE; case 'F': { /* Cell Format ;F<fmt-id><digits><alignment>: Single cell format. */ /* Format: D - default C - currency (extended) E - exponent F - fixed G - general, $ - dollar * - graph % - percent Alignment: DCGLR-X */ char ch1, alignment; if (3 == sscanf (str+1, "%c%d%c", &ch1, &tmp, &alignment)) { int a = -1; switch (alignment) { case 'S' : /* standard ? how does this differ from default */ case 'D' : a = GNM_HALIGN_GENERAL; break; case 'L' : a = GNM_HALIGN_LEFT; break; case 'R' : a = GNM_HALIGN_RIGHT; break; case 'C' : a = GNM_HALIGN_CENTER; break; case 'X' : a = GNM_HALIGN_FILL; break; default : break; } if (a >= 0) { if (style == NULL) style = gnm_style_new (); gnm_style_set_align_h (style, a); } } break; } /**************************************************/ /* Globals */ case 'E': state->pp.sheet->display_formulas = TRUE; break; case 'G': state->pp.sheet->hide_grid = TRUE; break; case 'H': state->pp.sheet->hide_col_header = TRUE; state->pp.sheet->hide_row_header = TRUE; break; case 'K': /* show commas ?? */ break; case 'Z': /* hide zeros */ state->pp.sheet->hide_zero = TRUE; break; /**************************************************/ case 'M' : /* row or col size * 20 or num cols for global */ sylk_parse_int (str+1, &size); break; case 'N' : { /* global font */ int size; if (2 == sscanf (str+1, "%d %d", &tmp, &size) && 1 <= tmp && tmp <= (int)state->fonts->len) { GnmStyle const *font = g_ptr_array_index (state->fonts, tmp-1); if (style == NULL) style = gnm_style_new (); is_default_style = TRUE; gnm_style_merge_element (style, font, MSTYLE_FONT_NAME); gnm_style_merge_element (style, font, MSTYLE_FONT_SIZE); /* It looks like the size from the id dominates * this size */ } break; } case 'P': if (sylk_parse_int (str+1, &tmp) && 0 <= tmp && tmp < (int)state->formats->len) { if (style == NULL) style = gnm_style_new (); gnm_style_set_format (style, g_ptr_array_index (state->formats, tmp)); } break; case 'S': for (str++ ; *str && *str != ';' ; str++) { switch (*str) { case 'I': if (style == NULL) style = gnm_style_new (); gnm_style_set_font_italic (style, TRUE); break; case 'D': if (style == NULL) style = gnm_style_new (); gnm_style_set_font_bold (style, TRUE); break; case 'M': if (sylk_parse_int (str+1, &tmp) && 1 <= tmp && tmp <= (int)state->fonts->len) { GnmStyle const *font = g_ptr_array_index (state->fonts, tmp-1); if (style == NULL) style = gnm_style_new (); gnm_style_merge_element (style, font, MSTYLE_FONT_NAME); gnm_style_merge_element (style, font, MSTYLE_FONT_SIZE); } str = (char *)" "; break; case 'S': /* seems to stipple things */ if (style == NULL) style = gnm_style_new (); gnm_style_set_pattern (style, 5); break; case 'T': style = sylk_set_border (style, MSTYLE_BORDER_TOP); break; case 'B': style = sylk_set_border (style, MSTYLE_BORDER_BOTTOM); break; case 'L': style = sylk_set_border (style, MSTYLE_BORDER_LEFT); break; case 'R': style = sylk_set_border (style, MSTYLE_BORDER_RIGHT); break; default: sylk_read_warning (state, "unhandled style S%c.", *str); } } break; case 'W': { int first, last, width; if (3 == sscanf (str+1, "%d %d %d", &first, &last, &width)) { /* width seems to be in characters */ if (first <= last && first < gnm_sheet_get_max_cols (state->pp.sheet) && last < gnm_sheet_get_max_cols (state->pp.sheet)) while (first <= last) sheet_col_set_size_pts (state->pp.sheet, first++ - 1, width*7.45, TRUE); } break; } case 'C': if (sylk_parse_int (str+1, &tmp)) full_col = tmp - 1; break; case 'R': if (sylk_parse_int (str+1, &tmp)) full_row = tmp - 1; break; case 'X': if (sylk_parse_int (str+1, &tmp)) state->pp.eval.col = tmp - 1; break; case 'Y': if (sylk_parse_int (str+1, &tmp)) state->pp.eval.row = tmp - 1; break; default: sylk_read_warning (state, "unhandled F option %c.", *str); } } if (full_col >= 0) { if (NULL != style) sheet_style_apply_col (state->pp.sheet, full_col, style); if (size > 0) sheet_col_set_size_pts (state->pp.sheet, full_col, size / 20.0, FALSE); } else if (full_row >= 0) { if (NULL != style) sheet_style_apply_row (state->pp.sheet, full_row, style); if (size > 0) sheet_row_set_size_pts (state->pp.sheet, full_row, size / 20.0, FALSE); } else if (NULL != style) { if (is_default_style) { GnmRange r; range_init_full_sheet (&r, state->pp.sheet); sheet_style_apply_range (state->pp.sheet, &r, style); } else sheet_style_apply_pos (state->pp.sheet, state->pp.eval.col, state->pp.eval.row, style); } return TRUE; }
G_MODULE_EXPORT void paradox_file_open (GOFileOpener const *fo, GOIOContext *io_context, WorkbookView *wb_view, GsfInput *input) { Workbook *wb; pxdoc_t *pxdoc; pxhead_t *pxh; pxfield_t *pxf; char *data; char *name; Sheet *sheet; GnmCell *cell; GnmValue *val = NULL; GOErrorInfo *open_error = NULL; guint row, i, j, offset; #ifdef PX_MEMORY_DEBUGGING PX_mp_init (); #endif #ifdef PX_MEMORY_DEBUGGING pxdoc = PX_new2 (gn_errorhandler, PX_mp_malloc, PX_mp_realloc, PX_mp_free); #else pxdoc = PX_new2 (gn_errorhandler, gn_malloc, gn_realloc, gn_free); #endif if (PX_open_gsf (pxdoc, input) < 0) { go_io_error_info_set (io_context, go_error_info_new_str_with_details ( _("Error while opening Paradox file."), open_error)); return; } pxh = pxdoc->px_head; PX_set_targetencoding (pxdoc, "UTF-8"); wb = wb_view_get_workbook (wb_view); name = workbook_sheet_get_free_name (wb, pxh->px_tablename, FALSE, TRUE); sheet = sheet_new (wb, name, 256, 65536); g_free (name); workbook_sheet_attach (wb, sheet); pxf = pxh->px_fields; for (i = 0 ; i < (guint) pxh->px_numfields; i++) { char str[30], *str2; char ctypes[26] = {'?', 'A', 'D', 'S', 'I', '$', 'N', '?', '?', 'L', '?', '?', 'M', 'B', 'F', 'O', 'G', '?', '?', '?', 'T', '@', '+', '#', 'Y', }; cell = sheet_cell_fetch (sheet, i, 0); if (pxf->px_ftype == pxfBCD) snprintf (str, 30, "%s,%c,%d", pxf->px_fname, ctypes[(int)pxf->px_ftype], pxf->px_fdc); else snprintf (str, 30, "%s,%c,%d", pxf->px_fname, ctypes[(int)pxf->px_ftype], pxf->px_flen); #if PXLIB_MAJOR_VERSION == 0 && (PXLIB_MINOR_VERION < 3 || (PXLIB_MAJOR_VERSION == 3 && PXLIB_MICRO_VERSION == 0)) /* Convert the field names to utf-8. This is actually in pxlib * responsibility, but hasn't been implemented yet. For the mean time * we *misuse* PX_get_data_alpha() */ PX_get_data_alpha (pxdoc, str, strlen (str), &str2); gnm_cell_set_text (cell, str2); pxdoc->free (pxdoc, str2); #else gnm_cell_set_text (cell, str); #endif pxf++; } { GnmRange r; GnmStyle *bold = gnm_style_new (); gnm_style_set_font_bold (bold, TRUE); sheet_style_apply_range (sheet, range_init (&r, 0, 0, pxh->px_numfields-1, 0), bold); } if ((data = (char *) pxdoc->malloc (pxdoc, pxh->px_recordsize, _("Could not allocate memory for record."))) == NULL) { go_io_error_info_set (io_context, go_error_info_new_str_with_details ( _("Error while opening Paradox file."), open_error)); return; } row = 1; for (j = 0; j < (guint)pxh->px_numrecords; j++) { pxdatablockinfo_t pxdbinfo; int isdeleted = 0; if (NULL != PX_get_record2 (pxdoc, j, data, &isdeleted, &pxdbinfo)) { offset = 0; pxf = pxh->px_fields; for (i = 0; i < (guint) pxh->px_numfields ; i++) { cell = sheet_cell_fetch (sheet, i, row); val = NULL; switch (pxf->px_ftype) { case pxfAlpha: { char *value; if (0 < PX_get_data_alpha (pxdoc, &data[offset], pxf->px_flen, &value)) { val = value_new_string_nocopy (value); /* value_set_fmt (val, field->fmt); */ } break; } case pxfShort: { short int value; if (0 < PX_get_data_short (pxdoc, &data[offset], pxf->px_flen, &value)) { val = value_new_int (value); } break; } case pxfAutoInc: case pxfLong: { long value; if (0 < PX_get_data_long (pxdoc, &data[offset], pxf->px_flen, &value)) { val = value_new_int (value); } break; } case pxfCurrency: case pxfNumber: { double value; if (0 < PX_get_data_double (pxdoc, &data[offset], pxf->px_flen, &value)) { val = value_new_float (value); if (pxf->px_ftype == pxfCurrency) value_set_fmt (val, go_format_default_money ()); } break; } case pxfTimestamp: { double value; if (0 < PX_get_data_double (pxdoc, &data[offset], pxf->px_flen, &value)) { value = value / 86400000.0; /* 693594 = number of days up to 31.12.1899 */ value -= 693594; val = value_new_float (value); value_set_fmt (val, go_format_default_date_time ()); } break; } case pxfLogical: { char value; if (0 < PX_get_data_byte (pxdoc, &data[offset], pxf->px_flen, &value)) { val = value_new_bool (value ? TRUE : FALSE); } break; } case pxfDate: { long value; int year, month, day; GDate *date; if (0 < PX_get_data_long (pxdoc, &data[offset], pxf->px_flen, &value)) { PX_SdnToGregorian (value+1721425, &year, &month, &day); date = g_date_new_dmy (day, month, year); val = value_new_int (go_date_g_to_serial (date, NULL)); value_set_fmt (val, go_format_default_date ()); g_date_free (date); } break; } case pxfTime: { long value; if (0 < PX_get_data_long (pxdoc, &data[offset], pxf->px_flen, &value)) { val = value_new_float (value/86400000.0); value_set_fmt (val, go_format_default_time ()); } break; } case pxfBCD: { char *value; if (0 < PX_get_data_bcd (pxdoc, &data[offset], pxf->px_fdc, &value)) { val = value_new_string_nocopy (value); } break; } case pxfMemoBLOb: { char *value; int size, mod_nr; if (0 < PX_get_data_blob (pxdoc, &data[offset], pxf->px_flen, &mod_nr, &size, &value)) { val = value_new_string_nocopy (value); } break; } default: val = value_new_string_nocopy ( g_strdup_printf (_("Field type %d is not supported."), pxf->px_ftype)); } if (val) gnm_cell_set_value (cell, val); offset += pxf->px_flen; pxf++; } if (pxh->px_filetype == pxfFileTypPrimIndex) { short int value; cell = sheet_cell_fetch (sheet, i++, row); if (0 < PX_get_data_short (pxdoc, &data[offset], 2, &value)) { val = value_new_int (value); gnm_cell_set_value (cell, val); } offset += 2; cell = sheet_cell_fetch (sheet, i++, row); if (0 < PX_get_data_short (pxdoc, &data[offset], 2, &value)) { val = value_new_int (value); gnm_cell_set_value (cell, val); } offset += 2; cell = sheet_cell_fetch (sheet, i++, row); if (0 < PX_get_data_short (pxdoc, &data[offset], 2, &value)) { val = value_new_int (value); gnm_cell_set_value (cell, val); } cell = sheet_cell_fetch (sheet, i++, row); val = value_new_int (pxdbinfo.number); gnm_cell_set_value (cell, val); } } row++; } pxdoc->free (pxdoc, data); PX_close (pxdoc); PX_delete (pxdoc); sheet_flag_recompute_spans (sheet); }
static void html_read_row (htmlNodePtr cur, htmlDocPtr doc, GnmHtmlTableCtxt *tc) { htmlNodePtr ptr; int col = -1; for (ptr = cur->children; ptr != NULL ; ptr = ptr->next) { if (xmlStrEqual (ptr->name, CC2XML ("td")) || xmlStrEqual (ptr->name, CC2XML ("th"))) { GString *buf; xmlBufferPtr a_buf; xmlAttrPtr props; int colspan = 1; int rowspan = 1; GnmCellPos pos; GnmStyle *mstyle; GSList *hrefs = NULL; GnmHLink *lnk = NULL; /* Check whether we need to skip merges from above */ pos.row = tc->row; pos.col = col + 1; while (gnm_sheet_merge_contains_pos (tc->sheet, &pos)) { col++; pos.col++; } /* Do we span across multiple rows or cols? */ props = ptr->properties; while (props) { if (xmlStrEqual (props->name, CC2XML ("colspan")) && props->children) colspan = atoi (CXML2C (props->children->content)); if (xmlStrEqual (props->name, CC2XML ("rowspan")) && props->children) rowspan = atoi (CXML2C (props->children->content)); props = props->next; } if (colspan < 1) colspan = 1; if (rowspan < 1) rowspan = 1; /* Let's figure out the content of the cell */ buf = g_string_new (NULL); a_buf = xmlBufferCreate (); mstyle = gnm_style_new_default (); if (xmlStrEqual (ptr->name, CC2XML ("th"))) gnm_style_set_font_bold (mstyle, TRUE); html_read_content (ptr, buf, mstyle, a_buf, &hrefs, TRUE, doc, tc); if (g_slist_length (hrefs) >= 1 && buf->len > 0) { /* One hyperlink, and text to make it * visible */ char *url; xmlBufferPtr h_buf = xmlBufferCreate (); hrefs = g_slist_reverse (hrefs); htmlNodeDump ( h_buf, doc, (htmlNodePtr)hrefs->data); url = g_strndup ( CXML2C (h_buf->content), h_buf->use); if (strncmp (url, "mailto:", strlen ("mailto:")) == 0) lnk = gnm_hlink_new ( gnm_hlink_email_get_type (), tc->sheet); else lnk = gnm_hlink_new ( gnm_hlink_url_get_type (), tc->sheet); gnm_hlink_set_target (lnk, url); gnm_style_set_hlink (mstyle, lnk); gnm_style_set_font_uline (mstyle, UNDERLINE_SINGLE); gnm_style_set_font_color (mstyle, gnm_color_new_go (GO_COLOR_BLUE)); g_free (url); xmlBufferFree (h_buf); } if (g_slist_length (hrefs) > 1 || buf->len <= 0) { /* Multiple links, * or no text to give hyperlink style, * so put them in a comment */ GSList *l; for (l = hrefs; l != NULL; l = l->next) { htmlNodeDump (a_buf, doc, (htmlNodePtr)l->data); xmlBufferAdd (a_buf, CC2XML ("\n"), -1); } } g_slist_free (hrefs); if (buf->len > 0) { GnmCell *cell = sheet_cell_fetch (tc->sheet, col + 1, tc->row); sheet_style_set_pos (tc->sheet, col + 1, tc->row, mstyle); gnm_cell_set_text (cell, buf->str); } else gnm_style_unref (mstyle); if (a_buf->use > 0) { char *name; name = g_strndup (CXML2C (a_buf->content), a_buf->use); cell_set_comment (tc->sheet, &pos, NULL, name, NULL); g_free (name); } g_string_free (buf, TRUE); xmlBufferFree (a_buf); /* If necessary create the merge */ if (colspan > 1 || rowspan > 1) { GnmRange range; GnmRange *r = ⦥ range_init (r, col + 1, tc->row, col + colspan, tc->row + rowspan - 1); gnm_sheet_merge_add (tc->sheet, r, FALSE, NULL); } col += colspan; } } }
static void html_read_content (htmlNodePtr cur, GString *buf, GnmStyle *mstyle, xmlBufferPtr a_buf, GSList **hrefs, gboolean first, htmlDocPtr doc, GnmHtmlTableCtxt *tc) { htmlNodePtr ptr; for (ptr = cur->children; ptr != NULL ; ptr = ptr->next) { if (ptr->type == XML_TEXT_NODE) { if (g_utf8_validate (ptr->content, -1, NULL)) html_append_text (buf, ptr->content); else g_string_append (buf, _("[Warning: Invalid text string has been removed.]")); } else if (ptr->type == XML_ELEMENT_NODE) { if (first) { if (xmlStrEqual (ptr->name, CC2XML ("i")) || xmlStrEqual (ptr->name, CC2XML ("em"))) gnm_style_set_font_italic (mstyle, TRUE); if (xmlStrEqual (ptr->name, CC2XML ("b"))) gnm_style_set_font_bold (mstyle, TRUE); } if (xmlStrEqual (ptr->name, CC2XML ("a"))) { xmlAttrPtr props; props = ptr->properties; while (props) { if (xmlStrEqual (props->name, CC2XML ("href")) && props->children) { *hrefs = g_slist_prepend ( *hrefs, props->children); } props = props->next; } } if (xmlStrEqual (ptr->name, CC2XML ("img"))) { xmlAttrPtr props; props = ptr->properties; while (props) { if (xmlStrEqual (props->name, CC2XML ("src")) && props->children) { htmlNodeDump (a_buf, doc, props->children); xmlBufferAdd (a_buf, CC2XML ("\n"), -1); } props = props->next; } } if (xmlStrEqual (ptr->name, CC2XML ("table"))) { Sheet *last_sheet = tc->sheet; int last_row = tc->row; tc->sheet = NULL; tc->row = -1; html_read_table (ptr, doc, tc->wb_view, tc); if (tc->sheet) { g_string_append_printf (buf, _("[see sheet %s]"), tc->sheet->name_quoted); xmlBufferAdd (a_buf, CC2XML (_("The original html file is\n" "using nested tables.")), -1); } tc->sheet = last_sheet; tc->row = last_row; } else html_read_content (ptr, buf, mstyle, a_buf, hrefs, first, doc, tc); } first = FALSE; } }
int gnumeric_style_set_font_bold(GnumericStylePtr style, int flag) { gnm_style_set_font_bold ((GnmStyle*)style, flag?TRUE:FALSE); return 0; }