Closed muhammadn closed 2 years ago
You can define attributes like this
IppAttribute("page-ranges", IppTag.RangeOfInteger, listOfIntRange)
and use it as parameter for printJob.
The template attributes are provided for convenience and ease of use.
Hi @gmuth . Thank you and i hope you had a good holiday.
I've tried above before i opened an issue but IppTemplateAttributes.kt
function arguments relies on IppTag.kt
so,
@JvmStatic
fun pageRanges(vararg range: List<IntRange>) =
IppAttribute("page-ranges", IppTag.RangeOfInteger, range)
the code above won't work because IppTag only validates it as IntRange
and not List<IntRange>
I can also try using String
as an argument with eg "1..2,2..3,10..15" like below:
@JvmStatic
fun pageRanges(vararg range: String) =
IppAttribute("page-ranges", IppTag.RangeOfInteger, listOf(range))
IppTag will cause an error because it does not match IntRange
If i modify IppTag which is a low level interaction, it will break while trying to communicate with Ipp
I understand your issue and have provided another method that supports Collection<IntRange>
.
Your first try is wrong because you really want to eliminate vararg completley. Your second try does not work because you again use vararg, but in fact really want just one String and also because you don't convert the string to the required type IntRange and therefore run into class cast exceptions (or failed checks I've implemented for better error handling).
pageRanges("1,3,4,10".toListOfIntRange())
now works together with extension
fun String.toListOfIntRange() = split(",").map { it.toInt()..it.toInt() }
Hi
I found out
pageRanges
allows multipleIntRange
, for example1..2,2..3
- for hardcoding, it would be okay but for programmatic use of the library i would have to useList<IntRange>
and an IntRange of1..2,2..3
is not valid.Is it possible we fix this to use String or List ? Example: String:
"1..2,3..4,6..6"
or List[1..2,3..4,5..6]
Programmatically
1..2,2..3
is not a validIntRange
Example code: