alignment
This commit is contained in:
@@ -2,7 +2,7 @@ defmodule LabelmakerWeb.Constants do
|
||||
@defaults %{
|
||||
color: "black",
|
||||
font: "Helvetica",
|
||||
gravity: "Center",
|
||||
align: "center",
|
||||
height: "",
|
||||
label: "",
|
||||
label_too_long: false,
|
||||
@@ -23,6 +23,12 @@ defmodule LabelmakerWeb.Constants do
|
||||
|> Map.keys()
|
||||
|> Enum.map(&Atom.to_string/1)
|
||||
|
||||
@alignments [
|
||||
"west",
|
||||
"center",
|
||||
"east"
|
||||
]
|
||||
|
||||
@colors [
|
||||
"black",
|
||||
"blue",
|
||||
@@ -85,6 +91,7 @@ defmodule LabelmakerWeb.Constants do
|
||||
def max_label_length, do: @max_label_length
|
||||
def max_label_error, do: @max_label_error
|
||||
def outlines, do: ["none" | @colors]
|
||||
def permitted_alignments, do: @alignments
|
||||
def permitted_keys, do: @permitted_keys
|
||||
def preview, do: @preview
|
||||
def sizes, do: @sizes
|
||||
|
||||
@@ -51,11 +51,11 @@ defmodule LabelmakerWeb.LabelController do
|
||||
]
|
||||
end
|
||||
|
||||
defp size_settings(args, %{gravity: gravity, height: height, width: width} = options) do
|
||||
defp size_settings(args, %{align: align, height: height, width: width} = options) do
|
||||
args ++
|
||||
[
|
||||
"-gravity",
|
||||
gravity,
|
||||
align,
|
||||
"-size",
|
||||
"#{width}x#{height}",
|
||||
"caption:#{String.slice(options.label, 0, Constants.max_label_length())}"
|
||||
|
||||
@@ -20,6 +20,9 @@ defmodule LabelmakerWeb.Tools do
|
||||
|> Map.take(Constants.permitted_keys())
|
||||
|> Map.new(fn {k, v} -> {String.to_atom(k), v} end)
|
||||
|> Enum.map(fn
|
||||
{:align, align} ->
|
||||
{:align, process_alignment(align |> String.downcase())}
|
||||
|
||||
{:font, font} ->
|
||||
{:font, Constants.font_map()[String.downcase(font)]}
|
||||
|
||||
@@ -48,6 +51,7 @@ defmodule LabelmakerWeb.Tools do
|
||||
pair
|
||||
end)
|
||||
|> Enum.filter(fn
|
||||
{:align, align} -> align in Constants.permitted_alignments()
|
||||
{:color, color} -> color in Constants.colors()
|
||||
{:font, font} -> font in Map.values(Constants.font_map())
|
||||
{:outline, outline} -> outline in Constants.outlines()
|
||||
@@ -59,6 +63,11 @@ defmodule LabelmakerWeb.Tools do
|
||||
Map.merge(Constants.defaults(), parameters)
|
||||
end
|
||||
|
||||
defp process_alignment("left"), do: "west"
|
||||
defp process_alignment("middle"), do: "center"
|
||||
defp process_alignment("right"), do: "east"
|
||||
defp process_alignment(alignment), do: alignment |> String.downcase()
|
||||
|
||||
defp process_height("", parameters) do
|
||||
parameters["width"] |> String.to_integer() |> max(0) |> min(Constants.max_height())
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user