(customenc && lang->encoding()->package() != Encoding::CJK)
? &bp.encoding() : lang->encoding();
+ // Some insets force specific encodings sometimes (e.g., listings in
+ // multibyte context forces singlebyte).
+ if (inset().forcedEncoding(enc, encodings.fromLyXName("iso8859-1"))) {
+ // Get the language outside the inset
+ size_t const n = depth();
+ for (size_t i = 0; i < n; ++i) {
+ Text const & otext = *slices_[i].text();
+ Language const * olang =
+ otext.getPar(slices_[i].pit()).getFont(bp, slices_[i].pos(),
+ otext.outerFont(slices_[i].pit())).language();
+ Encoding const * oenc = olang->encoding();
+ if (oenc->name() != "inherit")
+ return inset().forcedEncoding(enc, oenc);
+ }
+ // Fall back to buffer encoding if no outer lang was found.
+ return inset().forcedEncoding(enc, &bp.encoding());
+ }
+
// Inherited encoding (latex_language) is determined by the context
// Look for the first outer encoding that is not itself "inherit"
if (lang->encoding()->name() == "inherit") {
}
+Encoding const * InsetListings::forcedEncoding(Encoding const * inner_enc,
+ Encoding const * outer_enc) const
+{
+ // The listings package cannot deal with multi-byte-encoded
+ // glyphs, except if full-unicode aware backends
+ // such as XeTeX or LuaTeX are used, and with pLaTeX.
+ // Minted can deal with all encodings.
+ if (buffer().params().use_minted
+ || (buffer().params().encoding().package() == Encoding::japanese
+ && inner_enc->package() == Encoding::japanese)
+ || inner_enc->hasFixedWidth())
+ return 0;
+
+ // We try if there's a singlebyte encoding for the outer
+ // language; if not, fall back to latin1.
+ return (outer_enc->hasFixedWidth()) ?
+ outer_enc : encodings.fromLyXName("iso8859-1");
+}
+
+
void InsetListings::latex(otexstream & os, OutputParams const & runparams) const
{
string param_string = params().params();
bool encoding_switched = false;
Encoding const * const save_enc = runparams.encoding;
- // The listings package cannot deal with multi-byte-encoded
- // glyphs, except if full-unicode aware backends
- // such as XeTeX or LuaTeX are used, and with pLaTeX.
- bool const multibyte_possible = use_minted || runparams.isFullUnicode()
- || (buffer().params().encoding().package() == Encoding::japanese
- && runparams.encoding->package() == Encoding::japanese);
- if (!multibyte_possible && !runparams.encoding->hasFixedWidth()) {
+ Encoding const * const outer_encoding =
+ (runparams.local_font != 0) ?
+ runparams.local_font->language()->encoding()
+ : buffer().params().language->encoding();
+ Encoding const * fixedlstenc = forcedEncoding(runparams.encoding, outer_encoding);
+ if (fixedlstenc) {
// We need to switch to a singlebyte encoding, due to
// the restrictions of the listings package (see above).
// This needs to be consistent with
// LaTeXFeatures::getTClassI18nPreamble().
- Language const * const outer_language =
- (runparams.local_font != 0) ?
- runparams.local_font->language()
- : buffer().params().language;
- // We try if there's a singlebyte encoding for the current
- // language; if not, fall back to latin1.
- Encoding const * const lstenc =
- (outer_language->encoding()->hasFixedWidth()) ?
- outer_language->encoding()
- : encodings.fromLyXName("iso8859-1");
- switchEncoding(os.os(), buffer().params(), runparams, *lstenc, true);
- runparams.encoding = lstenc;
+ switchEncoding(os.os(), buffer().params(), runparams, *fixedlstenc, true);
+ runparams.encoding = fixedlstenc;
encoding_switched = true;
}
if (!uncodable.empty() && !runparams.silent) {
// issue a warning about omitted characters
// FIXME: should be passed to the error dialog
- if (!multibyte_possible && !runparams.encoding->hasFixedWidth())
+ if (fixedlstenc)
frontend::Alert::warning(_("Uncodable characters in listings inset"),
bformat(_("The following characters in one of the program listings are\n"
"not representable in the current encoding and have been omitted:\n%1$s.\n"