Skip to content

Commit

Permalink
feat: Added RendererSettings.ConnectDots.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Jan 25, 2024
1 parent 39fccdf commit ef1b6e4
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 10 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# QrCodes
Modern and efficient cross-platform QR code generation, rendering and serialization.
It contains various payloads and framework helpers for MAUI.

### 🔥 Features 🔥
- Use SkiaSharp/ImageSharp instead of System.Drawing to be cross-platform.
- Support latest dotnet versions.
- Generate QR code with logo image.
- Supports next payloads
- Allows many different styles.
- Supports many predefined payloads:
- BezahlCode
- Bitcoin like address
- Bookmark
Expand All @@ -33,11 +33,12 @@ It contains various payloads and framework helpers for MAUI.
- Base64
- SVG
- PostScript
- PDF
- FastPngRenderer - fast but not support all features
- Bitmap(.bmp) - fast but not support all features
- ImageSharp - powerful, allows many features and export formats
- SkiaSharp - powerful, allows many features and export formats
- PDF - powered by ImageSharp
- System.Drawing - legacy, only windows, not support all features
- Supports helpers for MAUI
- QrCodeSource - ImageSource to produce QR code
- QrCodeExtension markup extension - Simplifies usage of QrCodeSource
Expand Down Expand Up @@ -77,7 +78,7 @@ You can test all variants using [QrCodes.SampleApp MAUI app](sample)
xmlns:qr="clr-namespace:QrCodes.Maui;assembly=QrCodes.Maui"
```
```xml
<Image Source="{qr:QrCode 'Fixed value'}" />
<Image Source="{qr:QrCode 'https://t.me/havendv'}" />
```

### Links
Expand Down
21 changes: 16 additions & 5 deletions sample/DynamicExamplePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
<Label
HorizontalTextAlignment="Center"
Text="DrawQuietZones:" />
<CheckBox
x:Name="DrawQuietZonesCheckBox"
IsChecked="True" />
<Switch
x:Name="DrawQuietZonesSwitch"
IsToggled="True" />
<Label
HorizontalTextAlignment="Center"
Text="Logo:" />
Expand Down Expand Up @@ -91,6 +91,7 @@
<x:Static Member="Colors.Green" />
<x:Static Member="Colors.Blue" />
<x:Static Member="Colors.BlueViolet" />
<x:Static Member="Colors.Transparent" />
</x:Array>
</Picker.ItemsSource>
</Picker>
Expand All @@ -108,6 +109,7 @@
<x:Static Member="Colors.Green" />
<x:Static Member="Colors.Blue" />
<x:Static Member="Colors.BlueViolet" />
<x:Static Member="Colors.Transparent" />
</x:Array>
</Picker.ItemsSource>
</Picker>
Expand Down Expand Up @@ -143,6 +145,12 @@
x:Name="DotStylePicker"
ItemsSource="{qr:Enum Type={x:Type renderers:BackgroundType}}"
SelectedItem="{x:Static renderers:BackgroundType.Rectangle}" />
<Label
HorizontalTextAlignment="Center"
Text="ConnectDots:" />
<Switch
x:Name="ConnectDotsSwitch"
IsToggled="True" />
<Label
HorizontalTextAlignment="Center"
Text="{Binding Value, Source={x:Reference IconSizePercentSlider}, StringFormat='IconSizePercent: {0}'}" />
Expand All @@ -162,6 +170,7 @@
Minimum="0"
Value="6" />
<Image
Margin="10"
HeightRequest="400"
Source="{qr:QrCode Value={Binding Text,
Source={x:Reference ValueEntry}},
Expand All @@ -179,8 +188,8 @@
Source={x:Reference DarkColorPicker}},
LightColor={Binding SelectedItem,
Source={x:Reference LightColorPicker}},
DrawQuietZones={Binding IsChecked,
Source={x:Reference DrawQuietZonesCheckBox}},
DrawQuietZones={Binding IsToggled,
Source={x:Reference DrawQuietZonesSwitch}},
LogoSource={Binding SelectedItem,
Source={x:Reference LogoPicker}},
IconSizePercent={Binding Value,
Expand All @@ -191,6 +200,8 @@
Source={x:Reference BackgroundTypePicker}},
DotStyle={Binding SelectedItem,
Source={x:Reference DotStylePicker}},
ConnectDots={Binding IsToggled,
Source={x:Reference ConnectDotsSwitch}},
IconBackgroundColor={Binding SelectedItem,
Source={x:Reference IconBackgroundColorPicker}}}"
WidthRequest="400" />
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</ItemGroup>

<PropertyGroup Label="Nuget">
<Version>0.9.3</Version>
<Version>1.0.0</Version>
<Description>Modern cross-platform QR code generation, rendering and serialization.</Description>
<PackageTags>qr;qrcode;qrcoder;cross-platform;logo;modern;net8</PackageTags>
<GeneratePackageOnBuild Condition=" '$(Configuration)' == 'Release' ">true</GeneratePackageOnBuild>
Expand Down
2 changes: 2 additions & 0 deletions src/libs/QrCodes.Maui/QrCodeSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace QrCodes.Maui;
[DependencyProperty<Color>("IconBackgroundColor", DefaultValueExpression = "Colors.Transparent", OnChanged = nameof(OnChanged))]
[DependencyProperty<BackgroundType>("BackgroundType", DefaultValue = BackgroundType.Circle, OnChanged = nameof(OnChanged))]
[DependencyProperty<BackgroundType>("DotStyle", DefaultValue = BackgroundType.Rectangle, OnChanged = nameof(OnChanged))]
[DependencyProperty<bool>("ConnectDots", DefaultValue = true, OnChanged = nameof(OnChanged))]
[DependencyProperty<ImageSource>("LogoSource")]
public partial class QrCodeSource : StreamImageSource
{
Expand Down Expand Up @@ -75,6 +76,7 @@ private Task<Stream> RenderAsync(CancellationToken cancellationToken = default)
FileFormat = FileFormat,
Quality = Quality,
DotStyle = DotStyle,
ConnectDots = ConnectDots,
});

return Task.FromResult(stream);
Expand Down
24 changes: 24 additions & 0 deletions src/libs/QrCodes.SkiaSharp/Renderers/SkiaSharpRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,30 @@ private static void DrawQrCode(
default:
throw new ArgumentOutOfRangeException(nameof(settings), settings.BackgroundType, null);
}

if (settings is { ConnectDots: true, DotStyle: not BackgroundType.Rectangle })
{
if (modX < data.ModuleMatrix.Count - moduleOffset - 1 &&
data.ModuleMatrix[modY][modX] && data.ModuleMatrix[modY][modX + 1])
{
canvas.DrawRect(
x: (modX - moduleOffset + 0.5F) * settings.PixelsPerModule,
y: (modY - moduleOffset) * settings.PixelsPerModule,
w: settings.PixelsPerModule,
h: settings.PixelsPerModule,
paint: darkPaint);
}
if (modY < data.ModuleMatrix.Count - moduleOffset - 1 &&
data.ModuleMatrix[modY][modX] && data.ModuleMatrix[modY + 1][modX])
{
canvas.DrawRect(
x: (modX - moduleOffset) * settings.PixelsPerModule,
y: (modY - moduleOffset + 0.5F) * settings.PixelsPerModule,
w: settings.PixelsPerModule,
h: settings.PixelsPerModule,
paint: darkPaint);
}
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/libs/QrCodes/Renderers/Abstractions/RendererSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public class RendererSettings
/// </summary>
public BackgroundType DotStyle { get; set; } = BackgroundType.Rectangle;

/// <summary>
/// Connect the dots with lines. Default - true.
/// </summary>
public bool ConnectDots { get; set; } = true;

/// <summary>
///
/// </summary>
Expand Down

0 comments on commit ef1b6e4

Please sign in to comment.