<commit_before>define(['hgn!templates/settings-dialog.html', 'ReaderSettingsDialog_Keyboard', 'i18n/Strings', 'Dialogs', 'storage/Settings', 'Keyboard'], function(SettingsDialog, KeyboardSettings, Strings, Dialogs, Settings, Keyboard){
	var defaultSettings = {
        fontSize: 100,
        syntheticSpread: "auto",
        scroll: "auto",
        columnGap: 60
    }
    
    var getBookStyles = function(theme){
        var isAuthorTheme = theme === "author-theme";
    	var $previewText = $('.preview-text');
    	setPreviewTheme($previewText, theme);
    	var previewStyle = window.getComputedStyle($previewText[0]);
    	var bookStyles = [{selector: 'body', declarations: {
            backgroundColor: isAuthorTheme ? "" : previewStyle.backgroundColor,
            color: isAuthorTheme ? "" : previewStyle.color
        }}];
        return bookStyles;
    }
    var setPreviewTheme = function($previewText, newTheme){
        var previewTheme = $previewText.attr('data-theme');
        $previewText.removeClass(previewTheme);
        $previewText.addClass(newTheme);
        $previewText.attr('data-theme', newTheme);
    }
    
   var getWidthFactor = function(readerSettings){
        var gapNumber = readerSettings.columnGap/20;
        var widthFactor = 1.0;
        var isSyntheticSpread = readerSettings.syntheticSpread == "double";
        switch (gapNumber){
            case 1:
                widthFactor = isSyntheticSpread ? .95 : .90;
                break;
            case 2:
                widthFactor = isSyntheticSpread ? .89 : .80;
                break;
            case 3:
                widthFactor = isSyntheticSpread ? .83 : .70;
                break;
            case 4:
                widthFactor = isSyntheticSpread ? .77 : .60;
                break;
            case 5:
                widthFactor = isSyntheticSpread ? .70 : .50;
                break;
        }
        
        // TODO: this interferes with readium-shared-js layout measurements!!
        //return 1.0;
        return widthFactor;
    }
     
    var updateBookLayout = function(reader, readerSettings){
        var columnGap = 0;
        if ($('#reflowable-book-frame').length){
            var widthFactor = getWidthFactor(readerSettings);
            var iframeWidth = Math.floor($("#reading-area").width() * widthFactor);
            columnGap = readerSettings.columnGap;
            $('#epub-reader-frame').css({width: widthFactor * 100 + "%"});
        }
        else{
            $('#epub-reader-frame').css({width: "100%", overflow: "auto"});
        }
        return columnGap;
    }

    var updateReader = function(reader, readerSettings, doLayout){
        //TODO: columnGap is assigned to the same readerSettings.columnGap value in updateBookLayout?<commit_msg>fixes #134 (getWidthFactor() shifts scrollview to the right, page gets clipped)<commit_after>define(['hgn!templates/settings-dialog.html', 'ReaderSettingsDialog_Keyboard', 'i18n/Strings', 'Dialogs', 'storage/Settings', 'Keyboard'], function(SettingsDialog, KeyboardSettings, Strings, Dialogs, Settings, Keyboard){
	var defaultSettings = {
        fontSize: 100,
        syntheticSpread: "auto",
        scroll: "auto",
        columnGap: 60
    }
    
    var getBookStyles = function(theme){
        var isAuthorTheme = theme === "author-theme";
    	var $previewText = $('.preview-text');
    	setPreviewTheme($previewText, theme);
    	var previewStyle = window.getComputedStyle($previewText[0]);
    	var bookStyles = [{selector: 'body', declarations: {
            backgroundColor: isAuthorTheme ? "" : previewStyle.backgroundColor,
            color: isAuthorTheme ? "" : previewStyle.color
        }}];
        return bookStyles;
    }
    var setPreviewTheme = function($previewText, newTheme){
        var previewTheme = $previewText.attr('data-theme');
        $previewText.removeClass(previewTheme);
        $previewText.addClass(newTheme);
        $previewText.attr('data-theme', newTheme);
    }
    
   var getWidthFactor = function(readerSettings){
        var gapNumber = readerSettings.columnGap/20;
        var widthFactor = 1.0;
        var isSyntheticSpread = readerSettings.syntheticSpread == "double";
        switch (gapNumber){
            case 1:
                widthFactor = isSyntheticSpread ? .95 : .90;
                break;
            case 2:
                widthFactor = isSyntheticSpread ? .89 : .80;
                break;
            case 3:
                widthFactor = isSyntheticSpread ? .83 : .70;
                break;
            case 4:
                widthFactor = isSyntheticSpread ? .77 : .60;
                break;
            case 5:
                widthFactor = isSyntheticSpread ? .70 : .50;
                break;
        }
        
        // TODO: this interferes with readium-shared-js layout measurements!!
        //return 1.0;
        return widthFactor;
    }
     
    var updateBookLayout = function(reader, readerSettings){
        var columnGap = 0;
        if ($('#reflowable-book-frame').length && !$('#scrolled-content-frame').length){
            var widthFactor = getWidthFactor(readerSettings);
            var iframeWidth = Math.floor($("#reading-area").width() * widthFactor);
            columnGap = readerSettings.columnGap;
            $('#epub-reader-frame').css({width: widthFactor * 100 + "%"});
        }
        else{
            $('#epub-reader-frame').css({width: "100%", overflow: "auto"});
        }
        return columnGap;
    }

    var updateReader = function(reader, readerSettings, doLayout){
        //TODO: columnGap is assigned to the same readerSettings.columnGap value in updateBookLayout?
{'fraction_non_alphanumeric': 0.11772999647514981, 'fraction_numerical': 0.016743038420867114, 'mean_word_length': 2.2171201814058956, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1178510', 'n_tokens_mistral': 1608, 'n_tokens_neox': 1529, 'n_words': 342}