Skip to content
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

Landscape option added to base class #1892

Merged
merged 12 commits into from
Oct 23, 2023
Merged

Conversation

jodros
Copy link
Contributor

@jodros jodros commented Oct 13, 2023

I missed an option for a landscape mode so here it is.

jodros and others added 2 commits October 12, 2023 23:18
An orientation option was declared in the base class.
When it is "landscape", the values of x and y in papersize are swapped.

Just to explain what maybe could look redundant in classes/base.lua:92:

While testing this feature, it worked well for several times, but sometimes
- without touching the code - it suddenly stopped to work!

The problem is that the option.orientation must be passed as parameter
in SILE.papersize and in those times when it didn't work, its value was nil
even though it actually worked many times before without any
modification.

After some time I found out why: since there is no order in a loop using
pairs(), sometimes the loop in class:setOptions() was getting orientation
as the last element, so when SILE.papersize was called, the value of
options.orientation was indeed nil, so the solution should be just
set the orientation value to class.options before papersize.

modified:   classes/base.lua
modified:   core/papersize.lua
new file:   tests/landscape.sil
classes/base.lua Outdated Show resolved Hide resolved
core/papersize.lua Outdated Show resolved Hide resolved
tests/landscape.sil Outdated Show resolved Hide resolved
tests/landscape.sil Outdated Show resolved Hide resolved
@Omikhleia
Copy link
Member

Hello, that's something I considered too.

If it get accepted, it would need to be documented in the manual too. Not that we already have a PR on similar areas (#1853), so things will have to be done orderly.

Two small remarks in passing

  • In general, I believe it's best, when possible, to first open an enhancement issue before a PR (to get discussions before heading toward an implementation)
  • I see you merged master in your branch. Personally I would tend to recommend rebasing rather merging branches. It makes it easier when we change the target branch (e.g. to develop or other)

@jodros jodros marked this pull request as draft October 13, 2023 16:32
- modified:   classes/base.lua

Unnecessary spaces and indentation changes removed;

- modified:   documentation/c03-input.sil

Feature added to the documentation as a subsection of "Defining the paper size"

- modified:   core/papersize.lua

Now landscape argument is boolean.

- modified:   tests/landscape.sil
- new file:   tests/landscape.expected

The tests files as requested
@jodros
Copy link
Contributor Author

jodros commented Oct 13, 2023

Hello @Omikhleia , thanks for your reviewing and I appreciate your tips.

This PR touches several lines unrelated to your change (adding or removing spaces, changing indentation....) -- I think this should be avoided (or done separately when wanted, but I don't think it's the case here), notably;

I have a habit to always use automatic formatting, so some of these indentation changes were made so. I'll pay attention to this detail next times.

In general, I believe it's best, when possible, to first open an enhancement issue before a PR (to get discussions before heading toward an implementation)

Right, I'll remember that.

@jodros jodros marked this pull request as ready for review October 13, 2023 18:25
classes/base.lua Outdated Show resolved Hide resolved
classes/base.lua Outdated Show resolved Hide resolved
classes/base.lua Outdated Show resolved Hide resolved
@Omikhleia
Copy link
Member

This will conflict with #1853 which introduces a sheetsize in addition to the papersize -- and in the grand scheme of things, possibly, both could be distinct with respect to using landscape or not. We'd need to discuss it.

Copy link
Member

@alerque alerque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As already noted, the unrelated style changes need to be removed from this PR. I can barely make out what is going on, much less give it a good review. I'm actually quite happy to accept code style fixes, but only on their own not as part of other changes. Also many of these changes go against our usual coding styles and won't fly anyway.

Adding a landscape option is fine but we do need it to be clean.

@alerque
Copy link
Member

alerque commented Oct 13, 2023

Also have we thought about whether an enum option like this (two named options) is best or whether an orientation option that could allow more rotations (e.g. 4) would be more robust?

@alerque alerque added the enhancement Software improvement or feature request label Oct 13, 2023
@alerque alerque added this to the v0.x.y milestone Oct 13, 2023
@jodros jodros requested a review from alerque October 14, 2023 12:26
classes/base.lua Outdated Show resolved Hide resolved
core/papersize.lua Outdated Show resolved Hide resolved
tests/landscape.sil Outdated Show resolved Hide resolved
Copy link
Member

@alerque alerque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working with us to get this cleaned up. It's a simple option but it's worth implementing right so it is robust for future users.

Just a few nitpicks at this point mostly about boolean handling but there is one other logic issue I see.

core/papersize.lua Outdated Show resolved Hide resolved
classes/base.lua Outdated Show resolved Hide resolved
classes/base.lua Outdated Show resolved Hide resolved
jodros and others added 2 commits October 19, 2023 18:19
self.landscape is only passed to document state if there is an landscape input.
Now this variable is using the SU.boolean helper...
SU.boolean not used to check 'landscape' anymore

Co-authored-by: Caleb Maclennan <caleb@alerque.com>
alerque
alerque previously approved these changes Oct 19, 2023
@alerque alerque modified the milestones: v0.x.y, v0.14.13 Oct 19, 2023
@alerque
Copy link
Member

alerque commented Oct 21, 2023

@Omikhleia I'm pretty sure we can make a small adjustment and make this play nice with your PR for full bleed printing, but thinking about that does bring up a concern here. Are we going to have a problem with race conditions and the order (or Lua's non-deterministic order) of handling options?

@Omikhleia
Copy link
Member

@Omikhleia I'm pretty sure we can make a small adjustment and make this play nice with your PR for full bleed printing, but thinking about that does bring up a concern here. Are we going to have a problem with race conditions and the order (or Lua's non-deterministic order) of handling options?

My remark #1892 (comment) got closed, and the current implementation uses some workaround do avoid it. It does have code smell (or adds up to the existing one, regarding how class options are implemented). What else can I say?

@alerque
Copy link
Member

alerque commented Oct 23, 2023

I just rewrote this and even changed the way the existing papersize class option is handled. This should avoid the race condition, but also reduces the code smell rather than adding too it. Reduces not eliminates. Again we all know the crop marks package here needs replacing entirely. I did fix the landscape option so it can be set on custom papersizes not just presets, added a unit test for it, etc.

@jodros You might look over the contents of my commits for future reference. Some of the changes (like not handling the papersize option twice!) are fixes to bugs that existed before your PR, but others are fixes for things you didn't handle or not setting random variables you don't use, etc. No worries, just some pointers for the next go-round...

* Avoid possible race conditions
* Only set defaults once
* Handle landscape mode on custom paper sizes
* Pass option value to cropmarks package and allow override there
* Avoid setting usused variables
* Add code comments for the benefit of other coders and future self
@alerque alerque merged commit 2ff0b31 into sile-typesetter:master Oct 23, 2023
13 of 14 checks passed
alerque added a commit that referenced this pull request Oct 23, 2023
Co-authored-by: Caleb Maclennan <caleb@alerque.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Software improvement or feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants