codepage.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Purpose: constant values
  2. # Created: 10.03.2011
  3. # Copyright (c) 2011-2018, Manfred Moitzi
  4. # License: MIT License
  5. codepage_to_encoding = {
  6. '874': 'cp874', # Thai,
  7. '932': 'cp932', # Japanese
  8. '936': 'gbk', # UnifiedChinese
  9. '949': 'cp949', # Korean
  10. '950': 'cp950', # TradChinese
  11. '1250': 'cp1250', # CentralEurope
  12. '1251': 'cp1251', # Cyrillic
  13. '1252': 'cp1252', # WesternEurope
  14. '1253': 'cp1253', # Greek
  15. '1254': 'cp1254', # Turkish
  16. '1255': 'cp1255', # Hebrew
  17. '1256': 'cp1256', # Arabic
  18. '1257': 'cp1257', # Baltic
  19. '1258': 'cp1258', # Vietnam
  20. }
  21. encoding_to_codepage = {
  22. codec: ansi for ansi, codec in codepage_to_encoding.items()
  23. }
  24. def is_supported_encoding(encoding: str='cp1252') -> bool:
  25. return encoding in encoding_to_codepage
  26. def toencoding(dxfcodepage: str) -> str:
  27. for codepage, encoding in codepage_to_encoding.items():
  28. if dxfcodepage.endswith(codepage):
  29. return encoding
  30. return 'cp1252'
  31. def tocodepage(encoding: str) -> str:
  32. return 'ANSI_' + encoding_to_codepage.get(encoding, '1252')