Eneboo - Documentación para desarrolladores
|
00001 /*************************************************************************** 00002 AQOdsRow.h 00003 ------------------- 00004 begin : 12/12/2011 00005 copyright : (C) 2003-2011 by InfoSiAL S.L. 00006 email : mail@infosial.com 00007 ***************************************************************************/ 00008 /*************************************************************************** 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; version 2 of the License. * 00012 ***************************************************************************/ 00013 /*************************************************************************** 00014 Este programa es software libre. Puede redistribuirlo y/o modificarlo 00015 bajo los t�rminos de la Licencia P�blica General de GNU en su 00016 versi�n 2, publicada por la Free Software Foundation. 00017 ***************************************************************************/ 00018 00019 #ifndef AQODSROW_H_ 00020 #define AQODSROW_H_ 00021 00022 #include "odf-gen/row.h" 00023 00024 #include "AQOdsStyle.h" 00025 #include "AQOdsChart.h" 00026 #include "AQOdsImage.h" 00027 00028 static inline bool isXmlChar(const QChar &c) 00029 { 00030 // Characters in this range must be accepted by XML parsers. 00031 // Consequently characters outside of this range need to be escaped. 00032 00033 ushort uc = c.unicode(); 00034 00035 return uc == 0x9 00036 || uc == 0xA 00037 || uc == 0xD 00038 || 0x20 <= uc && uc <= 0xD7FF 00039 || 0xE000 <= uc && uc <= 0xFFFD; 00040 } 00041 00042 // ### AbanQ 00043 // to do compliant with the standar XML 1.0 00044 // 2.11 End-of-Line Handling and 3.3.3 Attribute-Value Normalization 00045 // see below encodeAttr 00046 static inline bool isEndOfLineChar(const QChar &c) 00047 { 00048 ushort uc = c.unicode(); 00049 00050 return uc == 0x9 00051 || uc == 0xA 00052 || uc == 0xD; 00053 } 00054 // ### AbanQ 00055 00056 static inline QString encodeAttr(const QString &str) 00057 { 00058 QString tmp(str); 00059 uint len = tmp.length(); 00060 uint i = 0; 00061 while (i < len) { 00062 if (tmp[(int)i] == '<') { 00063 tmp.replace(i, 1, "<"); 00064 len += 3; 00065 i += 4; 00066 } else if (tmp[(int)i] == '"') { 00067 tmp.replace(i, 1, """); 00068 len += 5; 00069 i += 6; 00070 } else if (tmp[(int)i] == '&') { 00071 tmp.replace(i, 1, "&"); 00072 len += 4; 00073 i += 5; 00074 } else if (tmp[(int)i] == '>' && i >= 2 && tmp[(int)i - 1] == ']' && tmp[(int)i - 2] == ']') { 00075 tmp.replace(i, 1, ">"); 00076 len += 3; 00077 i += 4; 00078 } 00079 // ### AbanQ 00080 // to do compliant with the standar XML 1.0 00081 // 2.11 End-of-Line Handling and 3.3.3 Attribute-Value Normalization 00082 else if (isEndOfLineChar(tmp[(int)i])) { 00083 QString repl = "&#x" + QString::number(tmp[(int)i].unicode(), 16) + ';'; 00084 tmp.replace(i, 1, repl); 00085 len += repl.length() - 1; 00086 i += repl.length(); 00087 } 00088 // ### AbanQ 00089 else if (!isXmlChar(tmp[(int)i])) { 00090 QString repl = "&#x" + QString::number(tmp[(int)i].unicode(), 16) + ';'; 00091 qWarning("AQOdsRow: not saving invalid character %s, the document will not be well-formed", repl.latin1()); 00092 repl = "?"; 00093 tmp.replace(i, 1, repl); 00094 len += repl.length() - 1; 00095 i += repl.length(); 00096 } else { 00097 ++i; 00098 } 00099 } 00100 00101 return tmp; 00102 } 00103 00104 class AQOdsRow : public Row 00105 { 00106 public: 00107 AQOdsRow(AQOdsSheet &sheet) : Row(sheet) {} 00108 00109 AQOdsRow &opIn(const AQOdsChart &value, 00110 uint column_span = 0, 00111 uint row_span = 0) { 00112 add_cell(value, column_span, row_span); 00113 return *this; 00114 } 00115 00116 AQOdsRow &opIn(const AQOdsImage &value, 00117 uint column_span = 0, 00118 uint row_span = 0) { 00119 add_cell(value, column_span, row_span); 00120 return *this; 00121 } 00122 00123 AQOdsRow &opIn(const AQOdsStyle &style) { 00124 add_style(style); 00125 return *this; 00126 } 00127 00128 AQOdsRow &opIn(const QString &value, 00129 uint column_span = 0, 00130 uint row_span = 0) { 00131 add_cell((const char *) encodeAttr(value), column_span, row_span); 00132 return *this; 00133 } 00134 00135 AQOdsRow &opIn(double value, 00136 uint column_span = 0, 00137 uint row_span = 0) { 00138 add_cell(value, column_span, row_span); 00139 return *this; 00140 } 00141 00142 AQOdsRow &coveredCell() { 00143 add_coveredcell(); 00144 return *this; 00145 } 00146 00147 AQOdsRow &addBgColor(const AQOdsColor &color) { 00148 add_bgcolor(color); 00149 return *this; 00150 } 00151 00152 AQOdsRow &addFgColor(const AQOdsColor &color) { 00153 add_fgcolor(color); 00154 return *this; 00155 } 00156 }; 00157 00158 #endif /* AQODSROW_H_ */