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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ The release run heads these entries with the version and opens a fresh
had set a global locale with a comma decimal separator. Adds a `fmt`
dependency.

- A sheet cell keeps its text on one line unless the file says to wrap it, read
into a new `TableCellStyle::wrap_text`. A line too long for its cell spills
over the empty cells beside it and is cut where the next has content. #238

- A spreadsheet view writes far less html for the same rendering: repeated style
blocks become classes, and a plain cell drops the run around it. The register
file's 500,000 cells fall from 121 MB to 38 MB. New
`HtmlConfig::spreadsheet_style_buffer`. #822

- New `Sheet::page_layout()`: the paper an ods states for a sheet, read from
the master page its table style names. Mirrored in the Python, JNI and Apple
bindings. Empty for xlsx, xls, numbers and csv.
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ set(ODR_SOURCE_FILES
"src/odr/internal/html/image_file.cpp"
"src/odr/internal/html/media_file.cpp"
"src/odr/internal/html/pdf_file.cpp"
"src/odr/internal/html/style_registry.cpp"
"src/odr/internal/html/text_file.cpp"
"src/odr/internal/html/xml_file.cpp"

Expand Down
3 changes: 3 additions & 0 deletions apple/include/OdrCoreObjC/ODRHtml.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ NS_SWIFT_NAME(HtmlConfig)
NSNumber *spreadsheetCellLimit NS_REFINED_FOR_SWIFT;
@property(nonatomic) BOOL spreadsheetLimitByContent;
@property(nonatomic) ODRHtmlTableGridlines spreadsheetGridlines;
/// How much of a sheet's body is held back while `<head>` collects the classes
/// its cells name.
@property(nonatomic) unsigned long long spreadsheetStyleBuffer;

@property(nonatomic) ODRHtmlViewportMode viewportMode;
/// Overrides `viewportMode` for spreadsheets when set.
Expand Down
2 changes: 2 additions & 0 deletions apple/include/OdrCoreObjC/ODRStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ NS_SWIFT_NAME(TableCellStyle)
@property(nonatomic, readonly) ODRDirectionalString *border;
/// `double`, boxed.
@property(nonatomic, readonly, nullable) NSNumber *textRotation;
/// `BOOL`, boxed.
@property(nonatomic, readonly, nullable) NSNumber *wrapText;

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
Expand Down
4 changes: 4 additions & 0 deletions apple/src/ODRHtml.mm
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ - (instancetype)initWithNativeConfig:(const odr::HtmlConfig &)config {
_spreadsheetLimitByContent = config.spreadsheet_limit_by_content ? YES : NO;
_spreadsheetGridlines =
static_cast<ODRHtmlTableGridlines>(config.spreadsheet_gridlines);
_spreadsheetStyleBuffer =
static_cast<unsigned long long>(config.spreadsheet_style_buffer);
_viewportMode = static_cast<ODRHtmlViewportMode>(config.viewport_mode);
_spreadsheetViewportMode =
config.spreadsheet_viewport_mode.has_value()
Expand Down Expand Up @@ -176,6 +178,8 @@ - (instancetype)initWithNativeConfig:(const odr::HtmlConfig &)config {
config.spreadsheet_limit_by_content = _spreadsheetLimitByContent == YES;
config.spreadsheet_gridlines =
static_cast<odr::HtmlTableGridlines>(_spreadsheetGridlines);
config.spreadsheet_style_buffer =
static_cast<std::uint64_t>(_spreadsheetStyleBuffer);
config.viewport_mode = static_cast<odr::HtmlViewportMode>(_viewportMode);
if (_spreadsheetViewportMode != nil) {
config.spreadsheet_viewport_mode = static_cast<odr::HtmlViewportMode>(
Expand Down
1 change: 1 addition & 0 deletions apple/src/ODRStyle.mm
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ + (instancetype)styleWithHandle:(const odr::TableCellStyle &)handle {
[ODRDirectionalMeasure directionalWithHandle:handle.padding];
result->_border = [ODRDirectionalString directionalWithHandle:handle.border];
result->_textRotation = box_number(handle.text_rotation);
result->_wrapText = box_number(handle.wrap_text);
return result;
}

Expand Down
2 changes: 2 additions & 0 deletions jni/java/app/opendocument/core/HtmlConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public final class HtmlConfig {

public boolean spreadsheetLimitByContent = true;
public HtmlTableGridlines spreadsheetGridlines = HtmlTableGridlines.SOFT;
/** How much of a sheet's body is held back while the head collects its classes. */
public long spreadsheetStyleBuffer = 128L << 20;

/** Initial zoom on mobile. */
public HtmlViewportMode viewportMode = HtmlViewportMode.AUTOMATIC;
Expand Down
5 changes: 4 additions & 1 deletion jni/java/app/opendocument/core/TableCellStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ public final class TableCellStyle {
public final DirectionalMeasure padding;
public final DirectionalString border;
public final Double textRotation;
public final Boolean wrapText;

TableCellStyle(
int horizontalAlign,
int verticalAlign,
Color backgroundColor,
DirectionalMeasure padding,
DirectionalString border,
Double textRotation) {
Double textRotation,
Boolean wrapText) {
this.horizontalAlign = HorizontalAlign.fromNative(horizontalAlign);
this.verticalAlign = VerticalAlign.fromNative(verticalAlign);
this.backgroundColor = backgroundColor;
this.padding = padding;
this.border = border;
this.textRotation = textRotation;
this.wrapText = wrapText;
}
}
15 changes: 13 additions & 2 deletions jni/src/jni_style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,13 @@ jobject make_table_cell_style(JNIEnv *env, const odr::TableCellStyle &style) {
env, "app/opendocument/core/TableCellStyle",
"(IILapp/opendocument/core/Color;"
"Lapp/opendocument/core/DirectionalMeasure;"
"Lapp/opendocument/core/DirectionalString;Ljava/lang/Double;)V",
"Lapp/opendocument/core/DirectionalString;Ljava/lang/Double;"
"Ljava/lang/Boolean;)V",
enum_code(style.horizontal_align), enum_code(style.vertical_align),
make_color(env, style.background_color),
make_directional_measure(env, style.padding),
make_directional_string(env, style.border),
box_double(env, style.text_rotation));
box_double(env, style.text_rotation), box_boolean(env, style.wrap_text));
}

jobject make_graphic_style(JNIEnv *env, const odr::GraphicStyle &style) {
Expand Down Expand Up @@ -421,6 +422,9 @@ jobject html_config_to_java(JNIEnv *env, const odr::HtmlConfig &config) {
const auto set_double = [&](const char *name, const double value) {
env->SetDoubleField(result, env->GetFieldID(cls, name, "D"), value);
};
const auto set_long = [&](const char *name, const jlong value) {
env->SetLongField(result, env->GetFieldID(cls, name, "J"), value);
};
const auto set_object = [&](const char *name, const char *signature,
jobject value) {
env->SetObjectField(result, env->GetFieldID(cls, name, signature), value);
Expand All @@ -446,6 +450,8 @@ jobject html_config_to_java(JNIEnv *env, const odr::HtmlConfig &config) {
set_object("spreadsheetCellLimit", "Ljava/lang/Long;",
box_long(env, config.spreadsheet_cell_limit));
set_boolean("spreadsheetLimitByContent", config.spreadsheet_limit_by_content);
set_long("spreadsheetStyleBuffer",
static_cast<jlong>(config.spreadsheet_style_buffer));
set_object("spreadsheetGridlines",
"Lapp/opendocument/core/HtmlTableGridlines;",
enum_from_code(env, "app/opendocument/core/HtmlTableGridlines",
Expand Down Expand Up @@ -538,6 +544,9 @@ odr::HtmlConfig html_config_from_java(JNIEnv *env, jobject config) {
const auto get_double = [&](const char *name) {
return env->GetDoubleField(config, env->GetFieldID(cls, name, "D"));
};
const auto get_long = [&](const char *name) {
return env->GetLongField(config, env->GetFieldID(cls, name, "J"));
};
const auto get_object = [&](const char *name, const char *signature) {
return env->GetObjectField(config, env->GetFieldID(cls, name, signature));
};
Expand Down Expand Up @@ -592,6 +601,8 @@ odr::HtmlConfig html_config_from_java(JNIEnv *env, jobject config) {
env->DeleteLocalRef(long_cls);
}
}
result.spreadsheet_style_buffer =
static_cast<std::uint64_t>(get_long("spreadsheetStyleBuffer"));
result.spreadsheet_limit_by_content =
get_boolean("spreadsheetLimitByContent");
{
Expand Down
2 changes: 2 additions & 0 deletions python/src/bind_html.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ void odr_python::bind_html(py::module_ &m) {
&odr::HtmlConfig::spreadsheet_limit_by_content)
.def_readwrite("spreadsheet_gridlines",
&odr::HtmlConfig::spreadsheet_gridlines)
.def_readwrite("spreadsheet_style_buffer",
&odr::HtmlConfig::spreadsheet_style_buffer)
.def_readwrite("viewport_mode", &odr::HtmlConfig::viewport_mode)
.def_readwrite("spreadsheet_viewport_mode",
&odr::HtmlConfig::spreadsheet_viewport_mode)
Expand Down
3 changes: 2 additions & 1 deletion python/src/bind_style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ void odr_python::bind_style(py::module_ &m) {
.def_readwrite("background_color", &odr::TableCellStyle::background_color)
.def_readwrite("padding", &odr::TableCellStyle::padding)
.def_readwrite("border", &odr::TableCellStyle::border)
.def_readwrite("text_rotation", &odr::TableCellStyle::text_rotation);
.def_readwrite("text_rotation", &odr::TableCellStyle::text_rotation)
.def_readwrite("wrap_text", &odr::TableCellStyle::wrap_text);

py::class_<odr::GraphicStyle>(m, "GraphicStyle")
.def(py::init<>())
Expand Down
4 changes: 4 additions & 0 deletions src/odr/html.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ struct HtmlConfig {
bool spreadsheet_limit_by_content{true};
/// Which gridlines a sheet paints.
HtmlTableGridlines spreadsheet_gridlines{HtmlTableGridlines::soft};
/// How much of a sheet's body is held back while `<head>` collects the
/// classes its cells name. Past it the head goes out with what it has, and a
/// style block first seen later stays inline.
std::uint64_t spreadsheet_style_buffer{128u << 20};

/// The zoom the view opens at; see @ref HtmlViewportMode.
HtmlViewportMode viewport_mode{HtmlViewportMode::automatic};
Expand Down
10 changes: 8 additions & 2 deletions src/odr/internal/html/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,21 @@ class File;

namespace odr::internal::html {

class StyleRegistry;

struct WritingState {
WritingState(HtmlWriter &out, const HtmlConfig &config,
HtmlResources &resources, const Logger &logger)
HtmlResources &resources, const Logger &logger,
StyleRegistry *styles = nullptr)
: m_out{&out}, m_config{&config}, m_resources(&resources),
m_logger{&logger} {}
m_logger{&logger}, m_styles{styles} {}

[[nodiscard]] HtmlWriter &out() const { return *m_out; }
[[nodiscard]] const HtmlConfig &config() const { return *m_config; }
[[nodiscard]] HtmlResources &resources() const { return *m_resources; }
[[nodiscard]] const Logger &logger() const { return *m_logger; }
/// Where repeated style blocks are deduplicated, or null where they are not.
[[nodiscard]] StyleRegistry *styles() const { return m_styles; }

/// The view's base direction, stated on its root.
[[nodiscard]] TextDirection direction() const { return m_direction; }
Expand All @@ -44,6 +49,7 @@ struct WritingState {
const HtmlConfig *m_config;
HtmlResources *m_resources;
const Logger *m_logger;
StyleRegistry *m_styles;
TextDirection m_direction{TextDirection::left_to_right};
};

Expand Down
Loading
Loading