1+ // ***********************************************************************
2+ // Assembly : OpenAC.Net.EscPos
3+ // Author : Rafael Dias
4+ // Created : 17-03-2022
5+ //
6+ // Last Modified By : Rafael Dias
7+ // Last Modified On : 17-03-2022
8+ // ***********************************************************************
9+ // <copyright file="BemaCodePageResolver.cs" company="OpenAC .Net">
10+ // The MIT License (MIT)
11+ // Copyright (c) 2014 - 2021 Projeto OpenAC .Net
12+ //
13+ // Permission is hereby granted, free of charge, to any person obtaining
14+ // a copy of this software and associated documentation files (the "Software"),
15+ // to deal in the Software without restriction, including without limitation
16+ // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17+ // and/or sell copies of the Software, and to permit persons to whom the
18+ // Software is furnished to do so, subject to the following conditions:
19+ // The above copyright notice and this permission notice shall be
20+ // included in all copies or substantial portions of the Software.
21+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24+ // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26+ // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27+ // DEALINGS IN THE SOFTWARE.
28+ // </copyright>
29+ // <summary></summary>
30+ // ***********************************************************************
31+
32+ using System ;
33+ using System . Collections . Generic ;
34+ using OpenAC . Net . Core . Extensions ;
35+ using OpenAC . Net . Devices . Commom ;
36+ using OpenAC . Net . EscPos . Command ;
37+ using OpenAC . Net . EscPos . Commom ;
38+ using OpenAC . Net . EscPos . Interpreter . Resolver ;
39+
40+ namespace OpenAC . Net . EscPos . Interpreter . Bematech
41+ {
42+ public sealed class BemaCodePageResolver : CommandResolver < CodePageCommand >
43+ {
44+ #region Constructors
45+
46+ public BemaCodePageResolver ( IReadOnlyDictionary < CmdEscPos , byte [ ] > dict ) : base ( dict )
47+ {
48+ }
49+
50+ #endregion Constructors
51+
52+ #region Methods
53+
54+ public override byte [ ] Resolve ( CodePageCommand command )
55+ {
56+ if ( command . PaginaCodigo . IsIn ( PaginaCodigo . pc852 , PaginaCodigo . pc1252 ) ) return new byte [ 0 ] ;
57+
58+ using var builder = new ByteArrayBuilder ( ) ;
59+
60+ var codePage = command . PaginaCodigo switch
61+ {
62+ PaginaCodigo . pc437 => new byte [ ] { 3 } ,
63+ PaginaCodigo . pc850 => new byte [ ] { 2 } ,
64+ PaginaCodigo . pc860 => new byte [ ] { 4 } ,
65+ PaginaCodigo . pcUTF8 => new byte [ ] { 8 } ,
66+ _ => throw new ArgumentOutOfRangeException ( )
67+ } ;
68+
69+ builder . Append ( new byte [ ] { CmdConst . ESC , 116 } ) ;
70+ builder . Append ( codePage ) ;
71+
72+ return builder . ToArray ( ) ;
73+ }
74+
75+ #endregion Methods
76+ }
77+ }
0 commit comments